本帖最后由 970253146 于 2015-6-13 00:25 编辑
之前曾经发帖求助,但问题还没得到解决。再描述一下我的问题。就是我现在用stm32f103rct6做spi从机。然后主机给出8个时钟时候。MISO引脚上接了逻辑分析仪看的数据,并不是我从机DR寄存器里面的那个值。比如说我从机DR里赋值是11110000,可是MISO上看到的波形是00111100.我主从时序配置都是一样的这个毋庸置疑,mode的slave跟master也没有选错。从机我是这样操作的:
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "sys.h"
#include "delay.h"
int main(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
RCC_DeInit(); //ÅäÖÃRCCʱÖÓ//
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); //³õʼ»¯GPIO¡¡//
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_15 | GPIO_Pin_13);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE ); //³õʼ»¯SPI
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
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_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStructure);
SPI_Cmd(SPI2, ENABLE);
SPI_I2S_SendData(SPI1,0xf0);
按道理来说,执行完SPI_I2S_SendData(SPI1,0xf0);数据就进去从机的DR里面了,时钟来之后就一位一位的出来,是可以用逻辑分析仪抓到11110000的波形的,但现在不是。求助啊,就这个问题困扰我两周了,我水平很低,实在没什么办法。主机是好的
|