The Program Wrote into ADS8328


#1

Hello~all,
I’m a student majoring in electronics. I am here cause my professional knowledge is limited.Could you help me out?
I’m involved in a project that writing program into ADS8328 by using STM32F103 . This is the datasheet of STM32F103C4T6A .I have been trying it for over weeks.I’m losing hearting. Please help me!
Code:

[code]#include “ADS8328.h”

void ADS8328_SPI_GPIO_Config(void)
{

        • /* defined GPI Ostructural body /
          GPIO_InitTypeDefGPIO_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();
          }[/code]
          I can’t really find what’s wrong! I’m in the edge of tears. Your help will be appreciated!

#2

Dear Ling,

This is a Forum about the Rust programming language. Your program is not written in Rust, but in C.
You may be interested in Rust on microcontrollers: http://blog.japaric.io/quickstart/

As it is, there is very little we can do for you: you don’t ask a specific question other than “it doesn’t work”, and questions about C really don’t have a place here on the Rust forums