Part Number:TMS320F28388D
进行单核SCI数据收发过程时,选择不使用FIFO模式,进行数据收发时,数据读取使用函数SCI_readCharBlockingNonFIFO(SCIA_BASE),将读取到的数据存放在字符串数组中,读取到却是一长串十六进制ascll码,并且只有前两位和7、8位15、16位是正确的,其余都是错误的,我发送的数据是一串带帧头帧尾的数据串,想将这串数据从助手中原封不动收回来,并且设置定时发送可以稳定收到#,101443.00,103.68373212,36.12000077,1510.5636,214.74,-1.27,1,3,40,-0.032,0.011,-0.029,0.068115,0.006653,0.063416,-0.006561,-0.069748,1.001160*,在串口助手中收到的数据截图为,我的代码如下,麻烦指教。
#include "driverlib.h" #include "device.h" #include "RS422.h" #include "string.h" #define SCI_EMPTY0 #define MAX_DATA_LENGTH 160 char dataString[MAX_DATA_LENGTH]; uint16_t bufferIndex = 0; uint8_t startReading = 0; char send1_flag = 0; void main(void) {uint16_t t = 0;Device_init();Device_initGPIO();GPIO_setMasterCore(28, GPIO_CORE_CPU1);GPIO_setPinConfig(GPIO_28_SCIA_RX);GPIO_setDirectionMode(28, GPIO_DIR_MODE_IN);GPIO_setPadConfig(28, GPIO_PIN_TYPE_STD);GPIO_setQualificationMode(28, GPIO_QUAL_ASYNC);GPIO_setMasterCore(29, GPIO_CORE_CPU1);GPIO_setPinConfig(GPIO_29_SCIA_TX);GPIO_setDirectionMode(29, GPIO_DIR_MODE_OUT);GPIO_setPadConfig(29, GPIO_PIN_TYPE_STD);GPIO_setQualificationMode(29, GPIO_QUAL_ASYNC);SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 230400, (SCI_CONFIG_WLEN_8 | SCI_CONFIG_STOP_ONE | SCI_CONFIG_PAR_NONE));SCI_resetChannels(SCIA_BASE);SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);SCI_enableModule(SCIA_BASE);SCI_performSoftwareReset(SCIA_BASE);Interrupt_initModule();Interrupt_initVectorTable();SCI_enableInterrupt(SCIA_BASE, (SCI_INT_RXRDY_BRKDT | SCI_INT_TXRDY));Interrupt_register(INT_SCIA_RX, sciaRXFIFOISR);Interrupt_enable(INT_SCIA_RX);Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);EINT;ERTM; #ifdef AUTOBAUD//// Perform an autobaud lock.// SCI expects an 'a' or 'A' to lock the baud rate.//SCI_lockAutobaud(SCIA_BASE); #endifwhile(1){if (send1_flag){send1_flag = 0;for (t = 0; t < bufferIndex; t++){if(dataString[t] == 0){continue;}SCI_writeCharBlockingNonFIFO(SCIA_BASE,dataString[t]);if(dataString[t] == '\0'){dataString[t] = 0;break;}dataString[t] = 0;}}} } __interrupt void sciaRXFIFOISR(void) {uint16_t receivedChar;while (SCI_isDataAvailableNonFIFO(SCIA_BASE) != SCI_EMPTY){receivedChar = SCI_readCharBlockingNonFIFO(SCIA_BASE);if (receivedChar == '#'){startReading = 1;bufferIndex = 0;dataString[bufferIndex++] = receivedChar;//continue;}if (startReading){if (receivedChar == '*'){dataString[bufferIndex++] = receivedChar;dataString[bufferIndex++] = '\r';dataString[bufferIndex++] = '\n';dataString[bufferIndex] = '\0';startReading = 0;}if (bufferIndex < MAX_DATA_LENGTH - 3){dataString[bufferIndex++] = receivedChar;}}}send1_flag = 1;SCI_clearOverflowStatus(SCIA_BASE);SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXRDY_BRKDT);Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9); }
Alice:
您好,
#和*的ASC码正确,说明波特率是正确的。
您发送的字符,接收以16进制显示,那么这个发送的字符串用16进制看是什么样的。
提供一个调试思路,字符发送有规律的如 a b c d等,以定位程序问题。
,
xiang zhang:
您好,
对于您的建议,我进行了以下尝试:
1.使用十六进制进行发送,收到的数据和之前是一样的;
2.根据您提供的思路,我在串口助手发送#ABCD后,收到的也只有前两位是对的;
下面是我串口调试助手收到的数据图片,麻烦您再指教一下,谢谢。
,
Alice:
您好,
从您的测试数据来看,字符B丢掉了,猜测是接收程序有问题,只来得及处理2个数据。
请只发送一次#ABCD,跟踪接收程序,看收到的数据是否正确。