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.

CC1352P: CC1352 UART in Collector example

Part Number: CC1352P

Hi All,

I am facing a problem with uart write callback. I am writing  55 bytes on uart, out of  55bytes 33 bytes are printing properly but the remaining 22 bytes are printing 0xFF on dock light. I attached the UART code here   

unsigned char Uart_Init(void)
{
// Semaphore Setup
Semaphore_Params_init(&gSemParams);
//set all sems in this module to be binary sems
gSemParams.mode = Semaphore_Mode_BINARY;

Semaphore_construct(&gUartSemStruct, 1, &gSemParams);
gUartSem = Semaphore_handle(&gUartSemStruct);

UART_init();
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.baudRate = 115200;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY ;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.readMode= UART_MODE_CALLBACK;
uartParams.dataLength = UART_LEN_8;
uartParams.stopBits = UART_STOP_ONE;
uartParams.writeMode = UART_MODE_CALLBACK;// UART_MODE_CALLBACK//UART_MODE_BLOCKING
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readTimeout = UART_WAIT_FOREVER;
uartParams.readCallback = UartReadCallback;
uartParams.writeCallback = UartWriteCB;

uart = UART_open(CONFIG_UART_0, &uartParams);

if (uart == NULL)
{
/* UART_open() failed */
//while (1);
return 0;
}

UART_control(uart, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);
uiReturnValue = UART_read(uart, cUartRxBuff, BUFF_LEN);
gUartWriteComplete = true;
return 1;
}

static void UartWriteCB(UART_Handle _handle, void *_buf, size_t _size)
{
uint32_t key = HwiP_disable();
gUartWriteComplete = true;
/* Exit critical section */
HwiP_restore(key);
}

static void UartReadCallback(UART_Handle _handle, void *_buf, size_t _size)
{
// Make sure we received all expected bytes
if (_size)
{
// If cleared, then read it
if(cUartBuf[0] == 0)
{
// Copy bytes from RX buffer to TX buffer
for(size_t i = 0; i < _size; i++)
{
cUartBuf[i] = ((uint8_t*)_buf)[i];
}
}
memset(_buf, '\0', _size);
Csf_setUart0Clock(1);
}
else
{
// Handle error or call to UART_readCancel()
UART_readCancel(uart);
}
}

bool UARTwriteString(char *_buffer, size_t _size)
{
//Error if no buffer
if((uart == NULL) || (_buffer == NULL) )
{
return 0;
}

bool uartReady = false;
/* Enter critical section so this function is thread safe*/
uint32_t key = HwiP_disable();
if (gUartWriteComplete)
{
uartReady = true;
}

/* Exit critical section */
HwiP_restore(key);

Semaphore_pend(gUartSem, BIOS_WAIT_FOREVER);

if (!uartReady)
{
/*
* If the uart driver is not yet done with the previous call to
* UART_write, then we can attempt to wait a small period of time.
*
* let's sleep 5000 ticks at 1000 tick intervals and keep checking
* on the readiness of the UART driver.
*
* If it never becomes ready, we have no choice but to abandon this
* UART_write call by returning CUI_PREV_WRITE_UNFINISHED.
*/
uint8_t i;
for (i = 0; i < 10; i++)
{
Task_sleep(1000);
uint32_t key = HwiP_disable();
if (gUartWriteComplete)
{
uartReady = true;
}
/* Exit critical section */
HwiP_restore(key);
if (uartReady)
{
break;
}
}

// If it still isn't ready, the only option we have is to ignore
// this print and hope that it wont be noticeable
if (!uartReady)
{
return 0;
}
}

key = HwiP_disable();
gUartWriteComplete = false;
HwiP_restore(key);

// UART_write ret val ignored because we are in callback mode. The result
// will always be zero.
if (0 != UART_write(uart,_buffer, _size))
{
Semaphore_post(gUartSem);
return 0;
}

Semaphore_post(gUartSem);
return 1;
}

why am i not getting proper data on docklight when i send more than 32bytes???

  • Hi H,

    Could you provide me a bit more information:

    1) Have you tried sniffing the UART lines to verify the Docklight assumption? 

    2) What controls your UART read? As the read callback is overwriting what seems to be the TX buffer, have you considered this case?

    3) You seem to have implemented quite a semi complex synchronization around the write call. The UART driver already do all these checks, why did you see a need for this logic compared to just checking the UART_write() return value? For example, it returns "UART_ERROR" if the TX is already in progress when being called.

  • Hi H,

    Could you provide me a bit more information:

    1) Have you tried sniffing the UART lines to verify the Docklight assumption? 

    2) What controls your UART read? As the read callback is overwriting what seems to be the TX buffer, have you considered this case?

    sorry, I'm not getting above two questions, please explain to me in detail

    3) You seem to have implemented quite a semi complex synchronization around the write call. The UART driver already do all these checks, why did you see a need for this logic compared to just checking the UART_write() return value? For example, it returns "UART_ERROR" if the TX is already in progress when being called.

    I'm unable to use the CUI_writeString function in other files. So I implemented uart write function and uart write callback as mentioned in cui file.

  • Hi H,

    1) Sniffing in this case means physically connecting for example a logic analyzer or oscilloscope to capture the data that goes over the bus. This is helpful as you can correlate what happens electrically which what the SW thinks happen.

    2) Your UART read callback is writing to the UART write buffer, correct?

    3) Why are you unable to use this function (sounds like some part of your app already does). Also, you do not need to re-implement what is in the CUI layer, that is only there to handle the extra ring buffer built into the layer.