Skip to content

Instantly share code, notes, and snippets.

@Overdrivr
Last active January 15, 2016 15:36
Show Gist options
  • Save Overdrivr/53479484d08465906c0f to your computer and use it in GitHub Desktop.
Save Overdrivr/53479484d08465906c0f to your computer and use it in GitHub Desktop.
serial/UART simple program and setup with Kinetis KL25Z
/* --
This program shows how to configure and output 'AB\n' on the USB serial port of a KL25Z
It is using processor expert and was tested on Kinetis Design Studio (KDS) ver 3.0.0
-- */
// 1. Add Processor Expert module AsynchroSerial
// In KDS, in the 'Components' view, right click on 'Components' then "Show components library"
// In the opened window, select the category 'Kinetis/Peripheral Drivers/Communication' and double-click on AsyncroSerial
// this will add the AsyncroSerial module to your project
// 2. Configuration
// Right click on the freshly created AsyncroSerial module in 'Components' view -> Inspector
// Set the baud-rate of your choice
// Set the receiver RxD pin to TPM2_CH0
// Set the transmitter TxD pin to TPM2_CH1
// EDIT : ISSUE WITH RX : If number of characters to be received > buffer size, nothing happens.
#include "ASerialLdd1.h"
// Call this function from main
void app()
{
LDD_TUserData* yourData;
LDD_TDeviceData* serialDriver = ASerialLdd1_Init(yourData);
uint8_t test[3] = {0x41,0x42,0x0D};
while(1)
{
// Send 'AB\n'
// You can check for errors using the debugger.
// Errors are defined in Generated_Code/PE_Error.h
LDD_TError err = ASerialLdd1_SendBlock(serialDriver, (LDD_TData *)test, 2);
// This must be called because interrupts are not enabled in AsyncroSerial module default config
// you must call this function after a write
// and regularly to poll for reception ?
ASerialLdd1_Main(serialDriver);
// Wait for some time
uint32_t i = 0;
for(i = 0 ; i < 10000 ; i++)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment