jasonasdf wrote on Monday, October 31, 2016:
Hi all,
currently using FreeRTOS V8.2.3, ported for Cortex-M4. The porting has been done by one of my ex-collegue and works well in one of the product, display unit as Master. Now I am using the same hardware platform, the same porting for the sensor unit as Slave. Basically, the sensor measure flow rate, display unit sends out commands via SPI to retrieve measurement value such as velocity, flow rate, temperature, as well as some basic settings as diameter.
In sensor unit,
while (1) {
Rev = SPIRx((INT08U*)&RxChar, 1, 5); //see below the definition
if (Rev == NON_ERROR) {
/Handler/
}
}
INT32U SPIRx(INT08U *buf, INT32U num, INT32U ms)
{
INT32U i;
for (i = 0; i < num; i++) {
if (xQueueReceive(SPI_RXQueue, &buf[i], ms) == pdTRUE) { // SPI_RXQueue sent out in SPI_ISR
continue;
} else {
return ERROR_SPI_TIMEOUT;
}
}
return NON_ERROR;
}
Firstly, the master side works well with other slaves.
Secondly, for (xQueueReceive(SPI_RXQueue, &buf[i], ms) , here what i first set the block time is 100ms, which i think is not important, because ISR can send out the value to Queue und unblock the task. However, I can only set this block time to 5ms, and very important thing is, i need to modify the master, DELAY 6ms before send out every commands. If i set this block time more, the master should delay more, otherwise, slave can not successfully received.
Thirdly, this block time also true in UART situation, the master need delay(20) more than slave, and the block time in slave need to adjust 18ms, thus, communication works. This is a compromise solution. not know what the root cause is.
Last, the usb task(which the coding is totally the same as in master, well-tested), if i comment other tasks, the PC can detect the slave, if SPI or UART task exists, than PC says unknown device, not connected. even if I set the blocktime of USB to 5ms
Rev = USBRead((INT08U*)&RxChar, 1, 5);
before
Rev = USBRead((INT08U*)&RxChar, 1, 100);
INT32U USBRead(INT08U *buf, INT32U num, INT32U ms)
{
INT32U i;
for (i = 0; i < num; i++) {
if (xQueueReceive(USB_RXQueue, &buf[i], ms) == pdTRUE) {
continue;
} else {
return ERROR_USB_COMM_TIMEOUT;
}
}
return NON_ERROR;
}
I have totally no idea why this would happen… confused me a lot. I hope someone can give me some hints. very appreciate that…