Thread: C Programming in ADS8328

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    3

    Question C Programming in ADS8328

    Hello~friends! How are you today?
    I am not very good because I met some troubles when doing my pprogram. So here I am to ask your guys some advice.
    Iím involved in a project that writing program into ADS8328(this is ADS8328's PDF ) by using STM32F103. I have been trying it for over weeks. Iím almost losing heart now.
    Code:
    #include "ADS8328.h"
     
    void ADS8328_SPI_GPIO_Config(void)
    {
    * * * * /* defined GPI Ostructural body */
    **GPIO_InitTypeDef**GPIO_InitStructure;*
    * * * **
    **/* start GPIO clock */
    * * * * ADS8328_SPI_GPIO_APBxClock_FUN ( ADS8328_SPI_CS_CLK, ENABLE );
    * * * * ADS8328_SPI_GPIO_APBxClock_FUN ( ADS8328_SPI_SCK_CLK, ENABLE );
    * * * * ADS8328_SPI_GPIO_APBxClock_FUN ( ADS8328_SPI_MISO_CLK, ENABLE );
    * * * * ADS8328_SPI_GPIO_APBxClock_FUN ( ADS8328_SPI_MOSI_CLK, ENABLE );
    * * * * ADS8328_SPI_GPIO_APBxClock_FUN ( ADS8328_SPI_EOC_CLK, ENABLE );
    * * * * ADS8328_SPI_GPIO_APBxClock_FUN ( ADS8328_SPI_CONVST_CLK, ENABLE );
    * * * **
    * * * * /* ADS8328_SPI_CS_PIN Pin initialization,and set it to be push-pull output */
    * * * * GPIO_InitStructure.GPIO_Pin = ADS8328_SPI_CS_PIN;
    **GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    **GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;* * * ** ** ***
    **GPIO_Init(ADS8328_SPI_CS_PORT, &GPIO_InitStructure);
    * * * **
    * * * * /* ADS8328_SPI_SCK_PIN Pin initialization,and set it to be push-pull output */
    **GPIO_InitStructure.GPIO_Pin = ADS8328_SPI_SCK_PIN;
    **GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    **GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;* * * ** ** ***
    **GPIO_Init(ADS8328_SPI_SCK_PORT, &GPIO_InitStructure);
    * * * **
    * * * * /* ADS8328_SPI_MOSI_PIN Pin initialization,and set it to be push-pull output */
    * * * * GPIO_InitStructure.GPIO_Pin = ADS8328_SPI_MOSI_PIN;
    **GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    **GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;* * * ** ** ***
    **GPIO_Init(ADS8328_SPI_MOSI_PORT, &GPIO_InitStructure);
    * * * **
    * * * * /* ADS8328_SPI_MISO_PIN  Pin initialization,and set it to be push-pull output */
    * * * * GPIO_InitStructure.GPIO_Pin = ADS8328_SPI_MISO_PIN;
    **GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    **GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    **GPIO_Init(ADS8328_SPI_MISO_PORT, &GPIO_InitStructure);
    * * * **
    * * * * /* ADS8328_SPI_CONVST_PIN  Pin initialization,and set it to be push-pull output */
    * * * * GPIO_InitStructure.GPIO_Pin = ADS8328_SPI_CONVST_PIN;
    **GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    **GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    **GPIO_Init(ADS8328_SPI_CONVST_PORT, &GPIO_InitStructure);
    * * * **
    * * * * /* ADS8328_SPI_EOC_PIN  Pin initialization,and set it to be push-pull output */
    **GPIO_InitStructure.GPIO_Pin = ADS8328_SPI_EOC_PIN;
    **GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    **GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    **GPIO_Init(ADS8328_SPI_EOC_PORT, &GPIO_InitStructure);
    * * * **
    * * * * /* ADS8328_SPI_CS_HIGH is high level */
    * * * * ADS8328_SPI_CS_HIGH;
    * * * **
    * * * * /* ADS8328_SPI_CONVST_HIGH is high level */
    * * * * ADS8328_SPI_CONVST_HIGH;
    * * * **
    * * * * /* 延迟500ms */
    * * * * SysTick_Delay_ms(500);
    * * * **
    }
     
    uint8_t ADS8328_SPI_Send4Bits(uint8_t data)
    {
    **uint8_t num = 0;
    **int i = 0;
    **data &= 0x0F;
    * * * * for(i=0;i<4;i++)
    * * * * {
    * * * * * * * * num <<= 1;
    * * * * * * * * ADS8328_SPI_SCK_HIGH;
    * * * * * * * * if((data & 0x08) >> 3)
    * * * * * * * * {
    * * * * * * * * * * * * ADS8328_SPI_MOSI_HIGH;
    * * * * * * * * }
    * * * * * * * * else
    * * * * * * * * {
    * * * * * * * * * * * * ADS8328_SPI_MOSI_LOW;
    * * * * * * * * }
    * * * * * * * * if(ADS8328_SPI_MISO_READ)
    * * * * * * * * {
    * * * * * * * * * * * * num++;
    * * * * * * * * }
    * * * * * * * * SysTick_Delay_us(5);
    * * * * * * * * ADS8328_SPI_SCK_LOW;
    * * * * * * * * SysTick_Delay_us(5);
    * * * * * * * * data <<= 1;
    * * * * }
    * * * * SysTick_Delay_us(5);
    * * * * return(num);
    }
     
    unsigned int ADS8328_SPI_Send16Bits(unsigned int data)
    {
    * * * * unsigned int num = 0;
    * * * * int i = 16;
    * * * * while(i--)
    * * * * {
    * * * * * * * * num <<= 1;
    * * * * * * * * ADS8328_SPI_SCK_HIGH;
    * * * * * * * * if((data & 0x8000) >> 15)
    * * * * * * * * {
    * * * * * * * * * * * * ADS8328_SPI_MOSI_HIGH;
    * * * * * * * * }
    * * * * * * * * else
    * * * * * * * * {
    * * * * * * * * * * * * ADS8328_SPI_MOSI_LOW;
    * * * * * * * * }
    * * * * * * * * if(ADS8328_SPI_MISO_READ)
    * * * * * * * * {
    * * * * * * * * * * * * num++;
    * * * * * * * * }
    * * * * * * * * SysTick_Delay_us(5);
    * * * * * * * * ADS8328_SPI_SCK_LOW;
    * * * * * * * * SysTick_Delay_us(5);
    * * * * * * * * data <<= 1;
    * * * * }
    * * * * SysTick_Delay_us(5);
    * * * * return(num);
    }
     
    unsigned int ADS8328_SPI_ReadHalfWord(void)
    {
    * * * * unsigned int num = 0;
    * * * * int i = 16;
    * * * * while(i--)
    * * * * {
    * * * * * * * * num <<= 1;
    * * * * * * * * ADS8328_SPI_SCK_HIGH;
    * * * * * * * * if(ADS8328_SPI_MISO_READ)
    * * * * * * * * {
    * * * * * * * * * * * * num++;
    * * * * * * * * }
    * * * * * * * * ADS8328_SPI_SCK_LOW;
    * * * * }
    * * * * SysTick_Delay_us(5);
    * * * * return(num);
    }
     
    void ADS8328_Write_CFR(unsigned int data)
    {
    * * * * ADS8328_SPI_CS_LOW;
    * * * * ADS8328_SPI_Send16Bits(data);
    * * * * ADS8328_SPI_CS_HIGH;
    }
     
    void ADS8328_Read_CFR(unsigned int *data1)
    {
    * * * * ADS8328_SPI_CS_LOW;
    * * * * *data1 = ADS8328_SPI_Send16Bits(0xC000)&0x0FFF;
    * * * * ADS8328_SPI_CS_HIGH;
    }
     
    unsigned int ADS8328_Read_Data(void)
    {
    * * * * unsigned int ret = 0;
    * * * * ADS8328_SPI_CS_LOW;
    * * * * SysTick_Delay_us(3);
    * * * * ADS8328_SPI_CS_HIGH;
    * * * **
    * * * * while(!ADS8328_SPI_EOC);
    * * * **
    * * * * ADS8328_SPI_CONVST_LOW;
    * * * * SysTick_Delay_us(1);
    * * * * ADS8328_SPI_CONVST_HIGH;
    * * * **
    * * * * ADS8328_SPI_CS_LOW;
    * * * * ret = ADS8328_SPI_ReadHalfWord();
    * * * * ADS8328_SPI_CS_HIGH;
    * * * **
    * * * * return ret;
    }
     
    void ADS8328_Init_Config(void)
    {
    * * * * unsigned int AD_Reg_Rd = 0;
    * * * * ADS8328_SPI_CONVST_LOW;
    * * * * SysTick_Delay_ms(100);
    * * * * ADS8328_SPI_CONVST_HIGH;
    * * * **
    * * * * ADS8328_SPI_CS_LOW;
    * * * * ADS8328_SPI_Send4Bits(0x0F);
    * * * * ADS8328_SPI_CS_HIGH;
    * * * * SysTick_Delay_us(100);
    * * * **
    * * * * ADS8328_Read_CFR(&AD_Reg_Rd);
    * * * **
    * * * * ADS8328_Write_CFR(0x0EFF);
    * * * * ADS8328_Read_CFR(&AD_Reg_Rd);
     
    * * * * * * * * ADS8328_Write_CFR(0x02FD);
    * * * * ADS8328_Read_CFR(&AD_Reg_Rd);
     
    * * * * * * * * ADS8328_Write_CFR(0x06FF);
    * * * * ADS8328_Read_CFR(&AD_Reg_Rd);
     
    * * * * * * * * ADS8328_Write_CFR(0x02FD);
    * * * * ADS8328_Read_CFR(&AD_Reg_Rd);
    }
     
    void ADS8328_Init(void)
    {
    * * * * ADS8328_SPI_GPIO_Config();
    * * * * ADS8328_Init_Config();
    }
    I canít really find whatís wrong!
    Thanks a lot.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,626
    What the hell are all those *'s for?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Salem View Post
    What the hell are all those *'s for?
    Probably visible white space from the OP's editor.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    806
    Quote Originally Posted by Salem View Post
    What the hell are all those *'s for?
    Some sort of codepage translation issue, etc...?

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    If you don't tell us what you're trying to do and what actually happens, we can't help you.
    Devoted my life to programming...

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,011
    Likely same post as on here Forum for Electronics

    Tim S.
    Last edited by stahta01; 05-19-2017 at 09:32 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2012, 01:03 AM
  2. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM

Tags for this Thread