新手入门
- 积分
- 16
- 金钱
- 16
- 注册时间
- 2018-9-22
- 在线时间
- 5 小时
|
1金钱
int main(void)
{
delay_init();
uart_init(9600);
LED_Init();
SPI1_Slave_Init();
while(1)
{
;
}
}
void SPI1_Slave_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1, ENABLE );
//Configure SPI2 pins: SCK, MISO and MOSI
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//1st phase: SPI1 slave
//SPI1 Config
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_RxOnly;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; //?NSS
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //MSB??
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable SPI2 RXNE interrupt*/
SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,ENABLE);
//Enable SPI2
SPI_Cmd(SPI2, ENABLE);
}
void SPI1_IRQHandler(void)
{
SPIReceiveBuff[SPIRxLen++] = SPI_I2S_ReceiveData(SPI2);
}
求助各位大神,我用的是stm32F103rct6,配置成从机模式,通过主机给其发送数据,仿真看,中断都进不去。。。
我的初始化配置过程有什么问题吗?
|
|