Other Parts Discussed in Thread: SYSBIOS
Tool/software: Code Composer Studio
Hi,everyone
I want to use Uart Emulator to connect a Uart device and access the device's data through modbus instructions. Now they communicate normally. But after running for a while, there was a problem with the data received by the RX.The order of this data is starting to get a bit messy.
This is correct data:
This is error data:
1.This error is not caused by the slave.because the data is rate.
2.I think it's cause by the RX FIFO.I don't know what to do.
3.The IO Mapping is DIO23 --- UART RX DIO24 --- UART TX. The SDK is simplelink_cc13x0_sdk_3_20_00_23. The Code Composer Studio Version: 9.1.0.00010.
4.please help me,thank you!
The is my code:
#include "ex_include_tirtos.h"
#include "scif.h"
#include "unistd.h"
#include <string.h>
#include <ti/sysbios/knl/Task.h>
#define BV(n) (1 << (n))
// Display error message if the SCIF driver has been generated with incorrect operating system setting
#if !(defined(SCIF_OSAL_TIRTOS_H) || defined(SCIF_OSAL_TIDPL_H))
#error "SCIF driver has incorrect operating system configuration for this example. Please change to 'TI-RTOS' or 'TI Driver Porting Layer' in the Sensor Controller Studio project panel and re-generate the driver."
#endif
// Display error message if the SCIF driver has been generated with incorrect target chip package
#ifndef SCIF_TARGET_CHIP_PACKAGE_QFN48_7X7_RGZ
#error "SCIF driver has incorrect target chip package configuration for this example. Please change to 'QFN48 7x7 RGZ' in the Sensor Controller Studio project panel and re-generate the driver."
#endif
// Task data
Task_Struct myTask;
Char myTaskStack[1024];
uint8_t cmd1[8] = {0x01, 0x04, 0x33, 0x1A, 0x00, 0x01, 0x1F, 0x49};
uint8_t cmd2[8] = {0x01, 0x04, 0x31, 0x1A, 0x00, 0x01, 0x1E, 0xF1};
uint8_t cmd3[8] = {0x01, 0x04, 0x32, 0x01, 0x00, 0x01, 0x6E, 0xB2};
uint8_t rev1[7];
uint8_t rev2[7];
uint8_t rev3[7];
uint8_t data[64];
void taskFxn(UArg a0, UArg a1) {
// Initialize the Sensor Controller
scifOsalInit();
scifInit(&scifDriverSetup);
// Start the UART emulator
scifExecuteTasksOnceNbl(BV(SCIF_UART_EMULATOR_TASK_ID));
// Enable baud rate generation
scifUartSetBaudRate(115200);//57600
// Enable RX (10 idle bit periods required before enabling start bit detection)
scifUartSetRxFifoThr(SCIF_UART_RX_FIFO_MAX_COUNT / 2);
scifUartSetRxTimeout(10 * 2);
scifUartSetRxEnableReqIdleCount(10 * 2);
scifUartRxEnable(1);
// Enable events (half full RX FIFO or 10 bit period timeout
scifUartSetEventMask(BV_SCIF_UART_ALERT_RX_FIFO_ABOVE_THR | BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT);
memset(&rev1,0,sizeof(rev1));
memset(&rev2,0,sizeof(rev2));
memset(&rev3,0,sizeof(rev3));
memset(&data,0,sizeof(data));
// Main loop
while (1) {
scifUartTxPutChars((char *)cmd1, 8);
Task_sleep(1000000/10);
scifUartRxGetChars((char *)rev1, 7);
memcpy(data,rev1,7);
scifUartTxPutChars((char *)cmd2, 8);
Task_sleep(1000000/10);
scifUartRxGetChars((char *)rev2, 7);
memcpy(data + 7,rev2,7);
scifUartTxPutChars((char *)cmd3, 8);
Task_sleep(1000000/10);
scifUartRxGetChars((char *)rev3, 7);
memcpy(data + 14,rev3,7);
scifUartTxPutChars((char *)data, 21);
Task_sleep(5000000/10);
memset(&rev1,0,sizeof(rev1));
memset(&rev2,0,sizeof(rev2));
memset(&rev3,0,sizeof(rev3));
memset(&data,0,sizeof(data));
}
} // taskFxn
int main(void) {
Task_Params taskParams;
// Initialize the board
Board_initGeneral();
// Configure the OS task
Task_Params_init(&taskParams);
taskParams.stack = myTaskStack;
taskParams.stackSize = sizeof(myTaskStack);
taskParams.priority = 3;
Task_construct(&myTask, taskFxn, &taskParams, NULL);
BIOS_start();
return 0;
}