|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2015-3-11 09:31:08
|
显示全部楼层
答以上各位,中断模式,调用CW中PE生成的代码,完全参考help的代码,如下。
例程是收发同数据量的buffer。
#define BLOCK_SIZE 4
uint8_t OutData[BLOCK_SIZE] = "0123";
uint8_t InpData[BLOCK_SIZE];
volatile bool DataReceivedFlag = FALSE;
volatile LDD_SPIMASTER_TError ComError = 0U;
LDD_TError Error;
LDD_TDeviceData *MySPIPtr;
void main(void)
{
...
MySPIPtr = SM1_Init(NULL); /* Initialization of SM1 component */
Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* Request data block reception */
Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE); /* Start transmission/reception */
while (!DataReceivedFlag) {}; /* Wait until data block is transmitted/received */
}
如果按照发1byte收4byte,应该改为:
Error = SM1_ReceiveBlock(MySPIPtr, InpData, 5); /* Request data block reception */
Error = SM1_SendBlock(MySPIPtr, OutData, 1); /* Start transmission/reception */
实际在示波器里看,收发的波形都正确,但是 Indata 里首字节会添加一个0xFF并丢失最后一个字节。
这么问题来了,0xFF怎么来的?如何避免?
|
|