Multiplexing bits in Pin Control Register

Status
Not open for further replies.

lelox93

Active member
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
Schermata 2018-01-02 alle 19.30.35.png
Why is this choice (ALT7) done? I was in the signal multiplexing chapter (10)
Schermata 2018-01-02 alle 19.41.10.jpg
but i didn't figure out why...
Can someone help me?
Best regards, Leo
 
The answer is definitively in the MUX chapter of the reference manual.
Here?
Schermata 2018-01-03 alle 14.22.13.png
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
 
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?
 
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?
Schermata 2018-01-03 alle 14.57.30.jpg

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?:confused:
 
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... ;)
 
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.
 
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.
 
Yes I got that.. But then it would mean to set "011" to MUX bits 10-8, that corresponds to Alternative 3, not ALT2..
Schermata 2018-01-03 alle 14.57.30.jpg
You see my doubt?
Thank you for the patience in answering!
 
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.
 
Status
Not open for further replies.
Back
Top