This project demonstrates UART through OpenSDA (character is printed back on console through the CDC port of the board) with the FRDM-KL46Z Board and Kinetis Design Studio.
I have created a demo project which communicates with a console on the host.
Before we start this project below are the pre-requisites:
- KDS 2.0.0 software tool from Freescale
(http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=KDS_IDE)
- FRDM-KL46Z Freedom development board
I have created a project by name “kl46-async uart” as shown below:
I am adding the component “AsynchroSerial” to our project which is the low-level driver used for this in Processor Expert is the ‘AsynchroSerial‘ component as shown
And i am adding the component “ Shell” as the Shell component offers a SendStr() method and other useful functionality.
So add the Shell component for the project, and use the AsynchroSerial with the ‘Serial’ template.
The AsynchroSerial settings are been done as shown below:
The interrupt is enabled as shown below:
As the CDC port of KL46 is connected to UART0 port i.e
RX port is connected to PTA1 :UART0_RX
TX port is connected to PTA2 :UART0_TX
And the baud rate is set to standard 9600
Next select CLS1 shell and make the settings as shown below:
The default serial is connected to AsynchroSerial component AS1
Generate the processor expert code by clicking the button shown below:
Now its time to add our code:
We are just reading the character from console through RX pin of UART port and same character is printing back to the console from TX pin of UART port.
I have declared a variable ch[10] as a char and storing the typed character from console into it.
Now build the project either by clicking on the small hammer button
or as shown below
You can see the compilation building the project
You can run this project either by going to Debug configuration and run by single step or by going to project properties > C/C++ Build > settings > Toolchains at the time of building the project opt for “create flash image” click apply and ok
Next select Tool settings and select Motorola S-record to generate SREC format as shown below:
Click on ‘Apply’ and ‘ok’
Now build the project, after successfully build you can find the “kl46-async uart.srec” file inside the Debug folder as shown
You can check it at below location
To run your program plug on KL46 board to your computer and open the corresponding COM port (com port number can be noted from device manager after plugging the board) and settings as shown below.
Now just drag and drop the srec file to the KL46 folder detected
You can see the output as shown below: type a character it is printed back on console through the CDC port of the board.
I have enclosed the project folder and SREC file for quick reference and testing.
Top Comments