This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hello,
I had bought TF mini plus which supports only UART and well supports for Arduino. In online they have given code for communication between arduino and TF mini-plus. My question is how to acces UART[0], UART[1]..... UART[9] individual element in TIVA C series using CCS code. In workbook of Tiva it is mentioned only UARTCharPut and UARTCharGet.
>Below is the code for ARDUINO , Keeping it as reference Kindly help me, how to code for TIVA C series and TF mini plus
int dist;
int strength;
float temperature;
int check;
int i;
int uart[9];
const int HEADER=0x59;
if (Serial1.available()) { //check if serial port has data input
if(Serial1.read() == HEADER) { //assess data package frame header 0x59
uart[0]=HEADER;
if (Serial1.read() == HEADER) { //assess data package frame header 0x59
uart[1] = HEADER;
for (i = 2; i < 9; i++) { //save data in array
uart[i] = Serial1.read();
}
check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
if (uart[8] == (check & 0xff)){ //verify the received data as per protocol
dist = uart[2] + uart[3] * 256; //calculate distance value
strength = uart[4] + uart[5] * 256; //calculate signal strength value
temprature = uart[6] + uart[7] *256;//calculate chip temprature
temprature = temprature/8 - 256;
Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print('\t');
Serial.print("strength = ");
Serial.print(strength); //output
Thank you.
uart[0] through uart[8] are simply the 9 integer array that is declared at the top of your code example. They are initialized in the for loop with calls to Serial1.read(). Your question should be how to perform the functions of Serial1.read(), Serial1.available() and Serial.print(). Download the TivaWare library if you have not done so already. Check the documentation file: C:\ti\TivaWare_C_Series-2.1.4.178\docs\SW-TM4C-DRL-UG-2.1.4.178.pdf. Chapter 30 describes the UART functions. You will also need to configure the UART pins and baud rate. I suggest you look at the example program: hello.c in C:\ti\TivaWare_C_Series-2.1.4.178\examples\boards\ek-tm4c123gxl\hello
Hello bob,
Thanks for your reply as per your suggestion. I studied and modified below code but still on Serial monitor I am able to see only the Data format of tf mini plus
please refer this = https://acroname.com/sites/default/files/assets/sj-pm-tfmini_plus_a04_product_mannual_en.pdf (page no - 12)
int main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
while (1)
{
if (UARTCharsAvail)
{
if(UARTCharGet(UART0_BASE) == HEADER) {
uart[0]=HEADER;
if (UARTCharGet(UART0_BASE) == HEADER) { //assess data package frame header 0x59
uart[1] = HEADER;
for (i = 2; i < 9; i++) { //save data in array
uart[i] = UARTCharGet(UART0_BASE);
}
check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
if (uart[8] == (check & 0xff)){ //verify the received data as per protocol
dist = uart[2] + uart[3]; //calculate distance value
strength = uart[4] + uart[5]; //calculate signal strength value
UARTprintf("dist = ");
UARTprintf(dist); //output measure distance value of LiDAR
UARTprintf('\t');
UARTprintf("strength = ");
UARTprintf(strength); //output
To use the function UARTPrintf() you need to call UARTStdioConfig() as shown in the hello.c example. Documentation for the UARTStdio functions are found in chapter 20 of: C:\ti\TivaWare_C_Series-2.1.4.178\docs\SW-TM4C-UTILS-UG-2.1.4.178.pdf