初始化代码如下:
/* configure SPI as SLAVE
SPI3.NSS ==> PA15
SPI3.SCK ==> PB3
SPI3.MISO ==> PB4
SPI3.MOSI ==> PB5
*/
/* enable clk */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |
RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE);
/* configure gpio pin */
GPIO_PinRemapConfig(GPIO_Remap_SPI3, DISABLE);
gpio.GPIO_Speed = GPIO_Speed_50MHz;
gpio.GPIO_Pin = GPIO_Pin_15;
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&gpio);
gpio.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&gpio);
gpio.GPIO_Pin = GPIO_Pin_4;
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&gpio);
/* configure NVIC */
nvic.NVIC_IRQChannel = SPI3_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 0;
nvic.NVIC_IRQChannelSubPriority = 1;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
/* configure spi */
spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
spi.SPI_Mode = SPI_Mode_Slave;
spi.SPI_DataSize = SPI_DataSize_8b;
spi.SPI_CPOL = SPI_CPOL_High;
spi.SPI_CPHA = SPI_CPHA_1Edge;
spi.SPI_NSS = SPI_NSS_Hard;
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
spi.SPI_FirstBit = SPI_FirstBit_MSB;
spi.SPI_CRCPolynomial = 7;
SPI_Init(SPI3, &spi);
SPI_I2S_ClearITPendingBit(SPI3, SPI_I2S_IT_RXNE);
SPI_I2S_ITConfig(SPI3,SPI_I2S_IT_RXNE,ENABLE);
SPI_Cmd(SPI3,ENABLE);
主机上的时序正常,有发送CLK,NSS,MOSI信号,但是从机无法进入SPI3,SPI_I2S_IT_RXNE中断。我将从机中的DR赋值为0,按理来说主机发送时钟时,从机也会把DR里的数据发送出来,但是实际测试MISO一直为高电平?
各位能否帮我看一下。
|