willie 发表于 2014-12-24 15:04:04

小贾-370388 发表于 2014-12-24 13:09
先看一下你的管脚配连接是否正确,再用示波器观察一下波形,先发0X03再发0X00 ...

void PORT_INIT(void)
{


GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOC, ENABLE);      
   

GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0);   
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_0);   
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_0);

       
       

/* Configure SPI1 PA5:SCK PA6:MISO PA7:MOSI------------------*/
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
       
       
       
/* Configure PA6:MISO ------------------*/
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;               
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;            
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;            
GPIO_Init(GPIOA, &GPIO_InitStructure);
       

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);





uint8_t SPI1_ReadWriteByte(uint8_t TxData)                                       
{
          
      while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
      SPI_SendData8(SPI1, TxData);

      while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
      return SPI_ReceiveData8(SPI1);

}

93C46 命令+address不是剛好8bit 那SPI_datasize_8b這一句是否要改成SPI_datasize_9b ?
是不是SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF)這裡有問題?
網上找的都是SPI模擬居多, 我打算用的是硬件SPI,多謝各位高手的指點....:D

willie 发表于 2014-12-25 21:18:32

willie 发表于 2014-12-24 15:04
void PORT_INIT(void)
{



write功能試出來了...謝謝各位樓上高手的指點有幫助到...:lol

唯一疑惑的是93c46數據格式9bit或10bit兩種 ...我用9bit格式寫入eeprom成功
但是spi數據是設定成spi_datasize_8b方式,而不是我原先認為應該設成spi_datasize_9b(或10b)

stm32f0 可以設成spi_datasieze範圍4b---16b,這樣的方式不就是方便針對不同數據長度的外設spi設成不同的數據格式長度嗎?怎麼我設成spi_datasize_8b也可以成功...?

damiaa 发表于 2015-1-9 09:12:25

SPI_DataSize_8b 吧

sasmike 发表于 2015-1-9 09:34:36

帮顶!!!
页: 1 [2]
查看完整版本: STM32F051R8 硬件SPI問題