大学生
最后登录1970-1-1
在线时间 小时
注册时间2014-7-24
|
请问各位做过这类通讯的高手们,为什么我用STM32驱动SI4432的时候,全速运行收发就是失败,失败原因是因为没有收发中断,没有收发中断就意味着没有数据。而我单步运行的时候,有收发中断,有正确的收发数据。请问这是怎么一回事?(SPI是没有问题的)
void communication_test()
{
unsigned char TxBuf[10] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
unsigned char RxBuf[10];
if(KEY_Scan())
{
RSSI_Check();
printf("¿aê¼ò»¸ö°′¼ü·¢ËíêμÑé\r\n");
SetTx_Mode();
SI4432_TX(TxBuf,10);
SetRx_Mode();
printf("òÑ×Ô¶ˉéèÖÃÎa½óêÕÄ£ê½\r\n");
Delay_ms(5);
}
if(SI4432_RX(RxBuf,10))
{
printf("½óêÕμ½êy¾Y£¬μè′yD£Ñé...\r\n");
for(i=0;i<10;i++)
{
if(RxBuf[i] == TxBuf[i])
{
check_num++;
}
}
if(check_num>8)
{
printf("the recive data:");
for(i=0;i<10;i++)
{
printf("%c",RxBuf[i]);
}
printf("¼ì2éíê±Ï...\r\n");
}
}
SetRx_Mode();
}
void SetTx_Mode()
{
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_1,0x01);//Ready
Delay_ms(5);
TX1_RX0;
Delay_ms(5);
printf("òÑéèÖÃÎa·¢éäÄ£ê½\r\n");
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_2,SI4432_Read_Register(OPERATING_FUNCTION_CONTROL_2)|0x01);
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_2,SI4432_Read_Register(OPERATING_FUNCTION_CONTROL_2)&0xFE);//·¢éäFIFOÇå0
Itstatus1 = SI4432_Read_Register(INTERRUPT_STATUS_1);
Itstatus2 = SI4432_Read_Register(INTERRUPT_STATUS_2); //ÇåÖD¶Ï±ê־λ
SI4432_Write_Register(INTERRUPT_ENABLE_1,0x04);//ê1Äüía2¿ÖD¶Ï
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_1,0x09);//ê1Äü·¢éäÄ£ê½
}
void SI4432_TX(unsigned char *TX_DataBuf,u8 Tx_Len)
{
uint8_t Time_out = 0;
SI4432_Write_Register(PREAMBLE_LENGTH,40);
SI4432_Write_Register(TRANSMIT_PACKET_LENGTH,Tx_Len);
SPI_Write_Buffer(0x7F,TX_DataBuf,Tx_Len);
Delay_ms(5);
while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11))
{
Time_out++;
if(Time_out >= Waiting_Time)
{
printf("·¢Ëí꧰ü\r\n");
Time_out = 0;
Delay_ms(10);
SI4432_Init();
break;
}
}
if(!(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11)))
{
Itstatus1 = SI4432_Read_Register(INTERRUPT_STATUS_1);
printf("\r\nItstatus1=%c\r\n",Itstatus1);
if((Itstatus1 & 0x04) == 0x04)
{
Itstatus1 = 0;
printf("·¢Ëí3é1|\r\n");
}
else
{
printf("·¢Ëí꧰ü\r\n");
}
}
}
void SetRx_Mode()
{
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_1,0x01);//Ready
Delay_ms(5);
TX0_RX1;//D¾Æ¬·½Ïò
Delay_ms(5);
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_2,SI4432_Read_Register(OPERATING_FUNCTION_CONTROL_2)|0x02);
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_2,SI4432_Read_Register(OPERATING_FUNCTION_CONTROL_2)&0xFD);//½óêÕÇå0
Itstatus1 = SI4432_Read_Register(INTERRUPT_STATUS_1);
Itstatus2 = SI4432_Read_Register(INTERRUPT_STATUS_2); //ÇåÖD¶Ï±ê־λ
SI4432_Write_Register(INTERRUPT_ENABLE_1,0x02);//ê1Äüía2¿ÖD¶Ï
SI4432_Write_Register(OPERATING_FUNCTION_CONTROL_1,0x05);//ê1Äü½óêÕÄ£ê½
}
u8 SI4432_RX(unsigned char *RX_DataBuf,u8 length)
{
uint8_t Rx_Flag = 0;
if(!(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11)))
{
Itstatus1 = SI4432_Read_Register(INTERRUPT_STATUS_1);
if((Itstatus1 & 0x02) == 0x02)
{
SPI_Read_Buffer(0x7F,RX_DataBuf,length);
Rx_Flag = 1;
}
else
{
Rx_Flag = 0;
}
}
return Rx_Flag;
}
void RSSI_Check()
{
u8 RSSI;
SetRx_Mode();
printf("\r\nDÅoÅÇ¿¶è:");
RSSI=SI4432_Read_Register(0x26);
printf("%d\r\n",RSSI);
}
|
|