打印

STM32F4 AD7694 SPI驱动

[复制链接]
248|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
博斯|  楼主 | 2018-7-30 09:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
void sys_spiInit(void)
{

    RCC->APB2ENR |= 1<<12;  //使能SPI1时钟
    SPI1->CR1|=0<<11;//8bit数据格式  
    SPI1->CR1|=0<<10;//全双工模式  
    SPI1->CR1|=1<<9; //软件nss 管理
    SPI1->CR1|=1<<8;
    SPI1->CR1|=0<<7; //MSBFirst  
    SPI1->CR1|=7<<3; //设置时钟Fsck = Fcpu/256
    SPI1->CR1|=1<<2; //SPI 主机
    SPI1->CR1|=0<<1; //空闲模式下 SCK为 0 CPOL=0
    SPI1->CR1|=0<<0; //数据采样从第1个时间边沿开始
    SPI1->CR1|=1<<6; //使能SPI1

}

u8 sys_spiSendRead(u8 byte)
{
  /* Loop while DR register in not emplty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  /* Send byte through the SPI1 peripheral */
  SPI_I2S_SendData(SPI1, byte);
  /* Wait to receive a byte */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  /* Return the byte read from the SPI bus */
  return SPI_I2S_ReceiveData(SPI1);
}

uint16_t ad7694_ReadData(void)
{
  unsigned long DataL = 0;
  unsigned long DataH = 0;
  unsigned long Ret = 0;
  
  GPIO_SetBits(GPIOA,GPIO_Pin_7);
  
  delay_us(6);
  
  GPIO_ResetBits(GPIOA,GPIO_Pin_7);  

  
  DataH = sys_spiSendRead(0xFF);
  DataH = DataH << 8;
  DataL = sys_spiSendRead(0xFF);
  Ret = DataH | DataL;
  return(Ret) ;   

}


AD7694是一个非常哈的A/D转换芯片,加上ADR431基准能够实现非常高的精度采集!(PS:STMF405RG单片机如果使用ST官方库 会导致SPI时钟信号木有,407却可以,所以我直接用寄存器写的)

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

412

主题

412

帖子

0

粉丝