Other Parts Discussed in Thread: CC2640R2F
Hi,
The implemented UART Callback at UART Echo example program but it does not work. I use svendbt code snippets from this post below.
Here is my modified UART echo example program. It prints the "Echoing characters:" so the UART works. I place a breakpoint at uartRxCb(), but when I press a key, it does not go to uartRxCb(). Why is that? Do you have any UART example programs for CC2640R2F Launchpad that demonstrates UART Callback?
/* * ======== uartecho.c ======== */ #include <stdint.h> #include <stddef.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> #include "string.h" /* Example/Board Header files */ #include "Board.h" #define BUFTYPE char #define PBUFTYPE char* #define BUFSIZE 1 UART_Handle uart; BUFTYPE rxBuf[BUFSIZE]; BUFTYPE txBuf[BUFSIZE]; static void uartRxCb(UART_Handle handle, void *buf, size_t count) { //Copy rxBuf to txBuf memset(txBuf, 0, BUFSIZE); memcpy(txBuf, rxBuf, count); UART_write(uart, txBuf, sizeof(txBuf)/sizeof(BUFTYPE)); } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { const char echoPrompt[] = "Echoing characters:\r\n"; UART_Params uartParams; /* Call driver init functions */ GPIO_init(); UART_init(); /* Turn on user LED */ GPIO_write(Board_GPIO_LED0, 1); /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.readMode = UART_MODE_CALLBACK; uartParams.writeMode = UART_MODE_BLOCKING; uartParams.readCallback = uartRxCb; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 115200; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { /* UART_open() failed */ while (1); } UART_write(uart, echoPrompt, sizeof(echoPrompt)); /* Loop forever echoing */ while (1) { UART_read(uart, &rxBuf, sizeof(rxBuf)/sizeof(BUFTYPE)); } }
- kel