EVE-4 平台移植

22 篇文章 0 订阅

本篇以STM32F030C8+FT800为例说明如何实现平台移植。

从驱动篇来看,平台移植只要实现API函数ft8xxSleep、spiWriteBytes、spiReadBytes就可以实现EVE芯片的指令操作。

为了能准确延时,所以采用Systick实现(也可以采用Timer实现)。因为STM32足够快,定时器采用1ms定时。

#define SYSTICK_TIMER ((SystemCoreClock / 1000) * TIMER_MS) //1ms

SysTick_Config(SYSTICK_TIMER);

然后在中断函数内计时

void SysTick_Handler(void)

{

              if (gTimerDelayCount != 0u)

              {

                             --gTimerDelayCount;

              }

}

ft8xxSleep函数如下:

void ft8xxSleep(uint16_t ms)

{

              gTimerDelayCount = ms;

              while (gTimerDelayCount != 0u);

}

 

spi使用的是STM32F030的SPI1,CS脚由GPIOA4控制。SPI1的GPIO初始化代码如下:

void gpioInit(void)

{

              GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

              /* SPI 1*/

              GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ;

              GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

              GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

              GPIO_Init(GPIOA, &GPIO_InitStructure);

 

              GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

              GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

              GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

              GPIO_Init(GPIOA, &GPIO_InitStructure);

              GPIO_SetBits(GPIOA,  GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7);

}

SPI配置函数

void spiCfg(SPI_TypeDef* SPIx, uint16_t prescaler)

{

              SPI_InitTypeDef  SPI_InitStructure;

              SPI_Cmd(SPIx, DISABLE);

              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 = prescaler;//SPI_BaudRatePrescaler_256;

              SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

              SPI_InitStructure.SPI_CRCPolynomial = 7;

              SPI_Init(SPIx, &SPI_InitStructure);

              /*Enable SPIx.NSS as a GPIO*/

              //SPI_SSOutputCmd(SPIx, ENABLE);

              SPI_Cmd(SPIx, ENABLE);

              SPI_RxFIFOThresholdConfig(SPIx,SPI_RxFIFOThreshold_QF);

              SPI_Cmd(SPIx, ENABLE);

}

定义一个全局变量gSPIx表示当前SPI驱动操作的SPI。

SPI_TypeDef* gSPIx;

 

SPI初始化函数如下:

void spiInit(uint16_t clk)

{

              gSPIx = SPI1;

              RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

              spiCfg(SPI1, SPI_BaudRatePrescaler_2);

}

SPI可以是全双工通信,函数如下:

void spiTransferBytes(uint8_t* wrBuf, uint8_t* rdBuf, uint16_t len)

{

              uint16_t i;

              for(i = 0; i < len; i++)

              {

                            // Loop while DR register in not emplty 

                      while( SPI_I2S_GetFlagStatus(gSPIx, SPI_I2S_FLAG_TXE) == RESET); 

                        

                        // Send byte through the SPI1 peripheral 

                            if(wrBuf != NULL)

                                          SPI_SendData8(gSPIx, wrBuf[i]);

                            else

                                           SPI_SendData8(gSPIx, 0xff);

 

                      // Wait to receive a byte 

                            //while( SPI_I2S_GetFlagStatus(gSPIx, SPI_I2S_FLAG_TXE)== RESET);

                            while( SPI_I2S_GetFlagStatus(gSPIx, SPI_I2S_FLAG_RXNE) == RESET); 

                            while( SPI_I2S_GetFlagStatus(gSPIx, SPI_I2S_FLAG_BSY) == SET);

                            if(rdBuf != NULL)

                                          rdBuf[i] = SPI_ReceiveData8(gSPIx);

                            else

                                          SPI_ReceiveData8(gSPIx);

              }

}

spiWriteBytes、spiReadBytes用宏定义定义:

#define spiWriteBytes(wrBuf, len)                 spiTransferBytes(wrBuf, NULL, len)

#define spiReadBytes(wrBuf, len)                   spiTransferBytes(NULL, rdBuf, len)

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值