Part Number: CC3220SF
Other Parts Discussed in Thread: SYSBIOS
Tool/software: Code Composer Studio
Hi,
I use "CC3220SF LAUNCHXL" Board. I run below code and at initial I got only "UART Callback Test" message from UART. But unfortunately my readcallback function doesn't run. I couldn't initialized the readcallback. What is the problem at my code? Could you please check and help me?
/*
* ======== uartecho.c ========
*/
#include <stdint.h>
#include <stddef.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>
/* Example/Board Header files */
#include "SKB_Board.h"
#define MAX_NUM_RX_BYTES 1000 // Maximum RX bytes to receive in one go
#define MAX_NUM_TX_BYTES 1000 // Maximum TX bytes to send in one go
const char test_message[] = "UART Callback Test:\r\n";
uint32_t wantedRxBytes; // Number of bytes received so far
uint8_t rxBuf[MAX_NUM_RX_BYTES]; // Receive buffer
uint8_t txBuf[MAX_NUM_TX_BYTES]; // Transmit buffer
static void readCallback(UART_Handle handle, void *rxBuf, size_t size);
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size);
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
UART_Handle handle;
UART_Params params;
/* Call driver init functions */
GPIO_init();
/* Configure the LED pin */
GPIO_setConfig(Output1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Turn on user LED */
GPIO_write(Output1, CC3220SF_GPIO_ON);
// Init UART
UART_init();
// Specify non-default parameters
UART_Params_init(¶ms);
params.baudRate = 115200;
params.writeMode = UART_MODE_CALLBACK;
params.writeDataMode = UART_DATA_BINARY;
params.writeCallback = writeCallback;
params.readMode = UART_MODE_CALLBACK;
params.readDataMode = UART_DATA_BINARY;
params.readCallback = readCallback;
handle = UART_open(DEBUG_UART, ¶ms);
//uart1 = UART_open(IMU_UART, &uartParams);
if (handle == NULL) {
/* UART_open() failed */
while (1);
}
UART_write(handle, test_message, sizeof(test_message));
//UART_write(uart1, echoPrompt, sizeof(echoPrompt));
wantedRxBytes = 16;
int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
while(1); // Wait forever
}
// Read callback function
static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
uint8_t i=0;
GPIO_toggle(Output1);
// Make sure we received all expected bytes
if (size == wantedRxBytes) {
// Copy bytes from RX buffer to TX buffer
for(i = 0; i < size; i++)
txBuf[i] = ((uint8_t*)rxBuf)[i];
// Echo the bytes received back to transmitter
UART_write(handle, txBuf, size);
// Start another read, with size the same as it was during first call to
// UART_read()
UART_read(handle, rxBuf, wantedRxBytes);
}
else {
// Handle error or call to UART_readCancel()
}
}
// Write callback function
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
// Do nothing
}