2015-10-25 08:42 PM
First i use Mode for SCK and MOSI was AF_PP but we read a strange value 0x42. and i Change it to AF_OD and it shows another value, that was 0xFE. and still not find the ready value of FT800 display. that should show 0x7c. I use STM32F103ZG.
Here is my Code:void SpiConfig(void){ GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = SPI1_SCK | SPI1_MOSI; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SPI1_MISO; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SPI1_PD | SPI1_CS; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);// RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 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_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); SPI_Cmd(SPI1, ENABLE);}Please Help me.. thanks #spi2015-10-26 08:02 AM
F1 coding tends to have MISO tagged as an Input, as I recall.
Double check your clock phase settings are correct.2015-11-18 07:35 PM
Thanks Clive1 I got the answer. I just add this code,
while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET);
on the SPI Transmit function. May be on the slave didnt receive last bit data.But Now I have a new problem on receive data on the master. We Always lost last bit data I have tried to add ''waiting busy flag'' before chip select gone high. I use Mode 0 SPI type. Could you suggest me how to troubleshoot this kind of problem? Where Should I start check? Thanks Very Much.