How to initialize/access UART???

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to initialize/access UART???

12,308 Views
olebon
Contributor I

I just started to study Kinetis and was really puzzled by absence of any example projects using a simple UART. All serial output is alway directed to printf() and there is no documentation at all with any information on how to select where the printf() output is directed, I was able to find uart_init (UART_MemMapPtr uartch, int sysclk, int baud), but again all I have is that source code. If try to use uart_putchar (UART_MemMapPtr channel, char ch) it requires some 'channel', that is no easy to guess. Is there any working UART example that shows how to access UART directly? 

 

0 Kudos
9 Replies

2,233 Views
mjbcswitzerland
Specialist V

Hi

 

You can also look at the uTasker project:

- UART user's guide: http://www.utasker.com/docs/uTasker/uTaskerUART.PDF

- Kinetis guide (developers notes in appendix) http://www.utasker.com/docs/KINETIS/uTaskerV1.4_Kinetis_demo.pdf

It allows debug output on any of the UARTs, Ethernet TELNET or USB CDC (or on a mixture of these) and also simulates UARTs and TELNET in real-time making development, debugging and learning simpler - see the CAN simulator video to get an idea: http://youtu.be/Ha8cv_XEvco

 

Regards

 

Mark

 

0 Kudos

2,233 Views
olebon
Contributor I

Thank you Mark, basically I found a simple way to do this:

  PORTC_PCR16=PORT_PCR_MUX(3);
  PORTC_PCR17=PORT_PCR_MUX(3);
  uart_init(UART3_BASE_PTR,100000000,19200);
 
  UART3_D=0xaa;

 

And the place where the printf is mapped is " k60_tower.h". The only thing I can't understand, why their documentation is so poor...

0 Kudos

2,232 Views
kashyapgada
Contributor III

Oleg Bondarenko wrote:

Thank you Mark, basically I found a simple way to do this:

  PORTC_PCR16=PORT_PCR_MUX(3);
  PORTC_PCR17=PORT_PCR_MUX(3);
  uart_init(UART3_BASE_PTR,100000000,19200);

  UART3_D=0xaa;

And the place where the printf is mapped is " k60_tower.h". The only thing I can't understand, why their documentation is so poor...

uart_init function's second parameter which you have written above "100000000" is incorrect. You have mentioned the frequency in Hz whereas the argument should be in Khz so three 0's need to be trimmed out of there.

Also for UART2, UART3, UART4 and UART5 operate on bus clock whose value is 50Mhz. Thus the second parameter of the uart_init function for UART 2 to 5 should be "50000"

For UART0 and UART1 which operate on Sysclock the 2nd Parameter of uart_init should be "100000".

Best Regards Kashyap

0 Kudos

2,232 Views
joelesco
Contributor III

Hi Kashyap Gada !

You seem to know about kinetis UART ! I'm really lost and like Oleg I don't find documentation !!


So can you say to me if that I understand is true or false ?


  PORTC_PCR16=PORT_PCR_MUX(3);   <-- That configure TX

  PORTC_PCR17=PORT_PCR_MUX(3);     <-- and this one RX ?

That I don't understand is "PORT_PCR_MUX(3)" cause we give that at the 2 pins and finally one is TX and the other RX ! Looks Magic ! ahaha

What is the code to say PORTC is UART 1 or 2 or 3 ?

Thanks a lot and I apologize for my english !!!! ( French people are not really good with foreign languages !!! )

Thanks again !

0 Kudos

2,232 Views
mjbcswitzerland
Specialist V

Hi Jo

  PORTC_PCR16=PORT_PCR_MUX(3);   <-- That configure TX

  PORTC_PCR17=PORT_PCR_MUX(3);     <-- and this one RX ?

The comments look to be reversed on the two lines since Port C16 is Rx to UART1 and Port C17 is Tx from UART1.

See the description of the PORTx_PCRY registers for selecting the peripheral function. PORT_PCR_MUX(3) is simply writing the value 3 to the correct location in the register so that the 3rd alternative function is selected, which is defined in turn as TX/RX for UART1 on these pins.

Regards

Mark

0 Kudos

2,232 Views
joelesco
Contributor III

Thanks again Mark ! The notation PORT_PCR_MUX was just so strange for me cause I associate MUX with multiplexage ... !

Encore merci à vous tous ! This community is just amazing !!!!!!!!!!!!!!

0 Kudos

2,232 Views
santiago_gonzal
NXP Employee
NXP Employee

Hello Joe,

In Kinetis, each pin has multiple functions. You must configure it to use the function you want to. In chapter 10 (Signal multiplexing and Pin Assignments) of Reference Manual you will find information about the fuctions each pin can do.

Here you have an example:

Regards,

Santiago

0 Kudos

2,233 Views
eli_hughes
Contributor V

Did you look at the KINETIS_SC examples?  Lots of UART stuff.  

 

 

0 Kudos

2,233 Views
eli_hughes
Contributor V

In fact that API is in the drivers section in the KINETIS_SC example.   Also check out the KQRUG document: Kinetis Peripheral Module Quick Reference  Reading the actually manual for the UART would  also be helpful to under stand how it works.

0 Kudos