STM32SPI interrupt can only accept the first two bytes each time
[Copy link]
The host SPI sends a group of numbers, such as A[]={"123456"}; the
slave SPI receives it using interrupts, and each data can be completely sent out, but the interrupt can only receive 12, and the other data cannot be received. Beginners need answers. The
host SPI sending function is as follows
/******
void SPI_Send_char(SPI_TypeDef* SPIx,uint16_t ch)
Send a character function
******/
void SPI_Send_char(SPI_TypeDef* SPIx,uint32_t ch)
{
if(SPIx==SPI1)
{
SPI_I2S_SendData(SPI1,ch);
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)!=SET);
}
if(SPIx==SPI2)
{
SPI_I2S_SendData(SPI2,ch);
}
if(SPIx==SPI3)
{
SPI_I2S_SendData(SPI3,ch);
while(SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_TXE)!=SET);
}
}
/****
SPI_SendString(SPI_TypeDef* SPIx, uint32_t *String)
Send character string function
******/
void SPI_SendString(SPI_TypeDef* SPIx, int8_t *String)
{
while(*String)
{
SPI_Send_char(SPIx,*String);
String++;
}
}
/*****
SPI_SendString_Lenth(SPI_TypeDef* SPIx, uint32_t *String,uint16_t len)
Send a string of a certain length
*******/
void SPI_SendString_Lenth(SPI_TypeDef* SPIx, int8_t *String,uint16_t len)
{
uint16_t i=0;
for(i=0;i<len;i++)
{
SPI1_End_Reindex%=SPI1_Buf_Lenth;
SPI_Send_char(SPIx,*(String+SPI1_End_Reindex));
}
}
Slave SPI interrupt acceptance function
void SPI1_IRQHandler()
{
if(SPI_I2S_GetITStatus(SPI1,SPI_I2S_IT_RXNE) !=RESET)
{
SPI1_Start_Reindex%=SP I1_Buf_Lenth;
SPI1_Buf[SPI1_Start_Reindex]=SPI_I2S_ReceiveData(SPI1);
SPI1_Start_Reindex++;
}
//if(SPI_I2S_GetITStatus(SPI1,SPI_I2S_IT_TXE)!=RESET)
//{
// SPI_SendString_Lenth(SPI1,SPI1_Buf,SPI1_Re cieve_Lenth);
// SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_TXE,DISABLE); //SPI transmit interrupt disabled
//}
}
|