Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Multiplexing bits in Pin Control Register

  1. #1

    Multiplexing bits in Pin Control Register

    Hi everyone,
    I'm trying to understand how void serial_begin(uint32_t divisor) function works (it is in the file serial1.c).
    Is this function that one that is called when the common "Serial.begin(baudrate);" is invoked in the arduino IDE?

    Then I walked through that ...|PORT_PCR_MUX(3); break; (line 120)
    that should be equal to set PORTB_PCR16 |= 0x00000700;
    I'm working with Teensy 3.2 and in the data sheet I found that to set those 3 bits is equal to use the alernative 7 in the pin mux control
    Click image for larger version. 

Name:	Schermata 2018-01-02 alle 19.30.35.png 
Views:	96 
Size:	293.8 KB 
ID:	12488
    Why is this choice (ALT7) done? I was in the signal multiplexing chapter (10)
    Click image for larger version. 

Name:	Schermata 2018-01-02 alle 19.41.10.jpg 
Views:	25 
Size:	130.9 KB 
ID:	12489
    but i didn't figure out why...
    Can someone help me?
    Best regards, Leo

  2. #2
    Could someone tell me if the addressed questions were not clear or appropriated?

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,890
    The answer is definitively in the MUX chapter of the reference manual.

  4. #4
    Quote Originally Posted by Theremingenieur View Post
    The answer is definitively in the MUX chapter of the reference manual.
    Here?
    Click image for larger version. 

Name:	Schermata 2018-01-03 alle 14.22.13.png 
Views:	17 
Size:	243.8 KB 
ID:	12495
    I have not the enlightment yet. Sorry.. Why JTAG?

    And what about the other question? Is serial_begin(uint32_t divisor) the same as Serial.begin(baudrate)?
    Thank you for the answer

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,890
    No JTAG, it MUST be UART. Thus, your error is before: PORT_PCR_MUX(3) sets the pin to ALT2.

    serial_begin(uint32_t divisor) is an internal helper function which initializes the UART with a clock divider and is (among other functions) called by Serial.begin(baudrate). But it's not a replacement since the baud rate has to be converted into a clock divider, depending on the different system clock rates.

    Why do you ask all that? What are you trying to achieve?

    Why can't you simply use Serial.begin() like everybody else?

  6. #6
    Quote Originally Posted by Theremingenieur View Post
    No JTAG, it MUST be UART. Thus, your error is before: PORT_PCR_MUX(3) sets the pin to ALT2.
    Thank you i misread the PORT_PCR_MUX(n) that is
    Code:
    #define PORT_PCR_MUX(n)              ((uint32_t)((n) & 7)<< 8))
    but this shouldn't be equal to:
    (3&7)<<8
    (...0011 & ...0111) <<8
    ..0011<<8
    ..0011 0000 0000
    ? And so set the Alternative 3?
    Click image for larger version. 

Name:	Schermata 2018-01-03 alle 14.57.30.jpg 
Views:	12 
Size:	130.0 KB 
ID:	12496

    serial_begin(uint32_t divisor) is an internal helper function which initializes the UART with a clock divider and is (among other functions) called by Serial.begin(baudrate). But it's not a replacement since the baud rate has to be converted into a clock divider, depending on the different system clock rates.
    Thank you! I'm studying it.

    Why do you ask all that? What are you trying to achieve?
    I'm trying to learn how to program the microcontroller by setting registers and also trying to acquire some knowledge about it!
    Am I in the right place to ask these questions?

  7. #7
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,890
    It's ok to ask, but it seems rather unusual to me. Most people asking questions here have a more or less precise idea of a project which they want to realize with their Teensy, thus, these "under the hood" questions are rather rare. There are people who dive into the Teensyduino core files, but most of them do so after having already studied the reference manual and also with a precise idea of an extended functionality or creating a new library in mind.

    But up to now, nobody wanted to re-invent the wheel...

  8. #8
    Quote Originally Posted by Theremingenieur View Post
    It's ok to ask, but it seems rather unusual to me. Most people asking questions here have a more or less precise idea of a project which they want to realize with their Teensy, thus, these "under the hood" questions are rather rare. There are people who dive into the Teensyduino core files, but most of them do so after having already studied the reference manual and also with a precise idea of an extended functionality or creating a new library in mind.

    But up to now, nobody wanted to re-invent the wheel...
    I'm using Teensy for my thesis experimental work, so yes, I have some specific goals to accomplish!
    For example in this part of my work I'm using teensy as a multichannel ADC to sample 2 EMG signals.
    Signals are amplified to be in the range [0; 3.3]V
    I want to set my sampling frequency at 1 kHz and as of now I used the PIT to acquire with the ADC and to print into the COM port the samples, that then are caught by LabVIEW VISA.
    I'm using teensy because this will evolve in a real-time buffering and processing of these signals to extract a control for a motor.
    Then I always struggled to understand serial communication and I'm digging deeply in it now for the first time.
    I'm studying with bad attention the manual maybe!
    By the way, I still cannot understand why (3&7)<<8, or PORT_PCR_MUX(3) does the job, since it is written Alternative 3 corresponding to 011.

  9. #9
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,890
    3 is 0011b and 7 is 0111b. 0011b & 0111b is still 0011b (bitwise AND) and thus still 3. The 0111b is just ANDed as a bitmask to prevent users from trying to go beyond the allowed 0 to 7 range.

  10. #10
    Yes I got that.. But then it would mean to set "011" to MUX bits 10-8, that corresponds to Alternative 3, not ALT2..
    Click image for larger version. 

Name:	Schermata 2018-01-03 alle 14.57.30.jpg 
Views:	16 
Size:	132.1 KB 
ID:	12497
    You see my doubt?
    Thank you for the patience in answering!

  11. #11
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,890
    You are looking at the wrong place in the table. We are talking about pin PTB16 (PORTB_PCR16) which is linked to UART0 with ALT3.

  12. #12
    Ok, now I got it. Thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •