我正在尝试学习微控制器的SPI外围设备。
这是从代码的一部分
volatile uint8_t rx_data[COUNT];
volatile uint8_t counter = 0;
volatile uint8_t data;
typedef enum
{
SPI_STATE_READY = 1, /* SPI initialized and ready for use */
SPI_STATE_BUSY = 2, /* SPI process is ongoing */
}spi_state_t;
typedef struct
{
spi_state_t spi_state;
}spi_handle;
spi_handle Spi;
int main(void)
{
initUSART();
printString("Slave\r\n");
DDRC = 0XFF;
spi_init_slave(); //Initialize slave SPI
Spi.spi_state = SPI_STATE_READY;
printString("OK\r\n");
//sei();
while(1)
{
while(Spi.spi_state != SPI_STATE_READY)
{
printString("NOT OKAY\r\n");
}
rx_slave(&Spi);
_delay_ms(50);
printString(rx_data);
_delay_ms(100);
}
}
但是代码在while循环中触发。它在串行终端中连续打印 NOOK OK