中滑好栗子 发表于 2017-1-4 11:35:23

stm32 f3 外拓AD5313R 应该如何配置和发数据

这是我写的代码:
SPI3_DAC :static void SPI3_Config(void)
{       
        SPI_InitTypeDefSPI_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;
       
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);       
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);        
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
       
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_6);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_6);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;                                        //СDA_SYNC
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                                        //SPI3_SCK
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_Init(GPIOC, &GPIO_InitStructure);
       
        /* Configure SPI3 pins:MISO and MOSI ---------------------------------*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Pin =GPIO_Pin_11;                                        //SPI3_MISO
GPIO_Init(GPIOC, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_12;                                        //SPI3_MOSI
GPIO_Init(GPIOC, &GPIO_InitStructure);

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_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI3, &SPI_InitStructure);

        SPI_CalculateCRC(SPI3, ENABLE);
        SPI_Cmd(SPI3, ENABLE);

        SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE);       
        SPI_SendData8(SPI3, 0X00);       
}

利用中断发送数据:
u8 TxBuffer = {0x21,0xff,0x30};

void SPI3_IRQHandler(void)
{
        static uint32_t Tx_Idx = 0;

GPIO_ResetBits(GPIOA, GPIO_Pin_15);
        GPIO_SetBits(GPIOC, GPIO_Pin_10);
if (SPI_I2S_GetITStatus(SPI3, SPI_I2S_IT_TXE) == SET)
{
    SPI_SendData8(SPI3, TxBuffer);
               
      if (Tx_Idx ==2)
      {
      SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, DISABLE);
                               
                                Tx_Idx = 0;
                               
                                GPIO_SetBits(GPIOA, GPIO_Pin_15);
                                GPIO_ResetBits(GPIOC, GPIO_Pin_10);
      }
}                 
}


求助 是为什么DAC_OUT无法输出电压。

中滑好栗子 发表于 2017-1-4 11:36:59

各位大神 帮帮忙啦:D

any012 发表于 2017-1-4 12:51:49

可以试试非中断方式。
AD的片子,很多都有官方的实例代码。对照着把通讯部分补上去就可以了。

lili0000 发表于 2017-1-4 13:32:47

官方的可以参考下

中滑好栗子 发表于 2017-1-4 13:44:04

any012 发表于 2017-1-4 12:51
可以试试非中断方式。
AD的片子,很多都有官方的实例代码。对照着把通讯部分补上去就可以了。 ...

我找过AD5313R的基本上都是用户手册 那么 请教官网应该是用什么搜(我也用过datasheets)

中滑好栗子 发表于 2017-1-4 13:45:09

lili0000 发表于 2017-1-4 13:32
官方的可以参考下

嗯 请教下 应该搜索什么 我搜索过AD5313R 但是都是用户手册 没有显示官网之类的东西

any012 发表于 2017-1-4 14:17:54

中滑好栗子 发表于 2017-1-4 13:44
我找过AD5313R的基本上都是用户手册 那么 请教官网应该是用什么搜(我也用过datasheets) ...

抱歉,我有点想当然了。
搜了下ADI官网,ADR5313R官网上找不到编程参考。

建议用示波器看下SPI相关引脚波形。

中滑好栗子 发表于 2017-1-4 14:35:33

any012 发表于 2017-1-4 14:17
抱歉,我有点想当然了。
搜了下ADI官网,ADR5313R官网上找不到编程参考。



嗯好的 谢谢
页: [1]
查看完整版本: stm32 f3 外拓AD5313R 应该如何配置和发数据