This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1298: ADS1298 sample code in c language

Genius 3300 points
Part Number: ADS1298

is there sample code for reading ADS1298 in c language. 

  • Hello,

    Unfortunately we do not have any sample code for this device.
    Perhaps within other online communities regarding software coding there has been something developed that may help, but we do not maintain any.

    Regards
    Cynthia
  • Hi,

    this is code i have taken reference from arduino on internet.

    I am able to read 0x92 on ID register..

    can u check the seqence/commands  of code is its ok?

    #include <SPI.h>
    
    #define MOSI1    51 //MOSI
    #define MISO1    50 //MISO
    #define CLK1     52 //SCK
    
    #define PIN_CS     2
    #define PIN_RESET  3
    #define PIN_START  4
    #define PIN_DRDY   5
    
    #define READ       0x20
    #define WRITE      0x40
    
    #define ID         0x00
    #define SDATAC     0x11
    
    
    uint8_t debug_msg = 1U;
    String sep = "---------------------------------------------------------";
    String hex_to_char(int hex_in) {
      int precision = 2;
      char tmp[16];
      char format[128];
      sprintf(format, "0x%%.%dX", precision);
      sprintf(tmp, format, hex_in);
      //Serial.print(tmp);
      return(String(tmp));
    }
    
    
    
    uint8_t read_byte(uint8_t reg_addr)
    {
        uint8_t out = 0;
        
        digitalWrite(PIN_CS, LOW);
        
        SPI.transfer(0x20 | reg_addr);
        delayMicroseconds(5);
        SPI.transfer(0x00);
        delayMicroseconds(5);
        
        out = SPI.transfer(0x00);
        delayMicroseconds(1);
        digitalWrite(PIN_CS, HIGH);
        
        if(debug_msg)
        {
            Serial.println(sep);
            Serial.println( "sent:\t" + hex_to_char(reg_addr) );
            Serial.println( "recieved:\t" + hex_to_char(out) );
        }
        
        return(out);
    }
    
    
    void send_command(uint8_t cmd)
    {
        digitalWrite(PIN_CS, LOW);
        delayMicroseconds(5); // 5 = 6us at 32
        SPI.transfer(cmd);
        delayMicroseconds(10);
        digitalWrite(PIN_CS, HIGH);
    }
    
    
    void setup() 
    {
        Serial.begin(9600);
    
        
        pinMode(CLK1, OUTPUT);
        pinMode(MISO1, INPUT); 
        pinMode(MOSI1, OUTPUT);
        pinMode(PIN_CS,    OUTPUT);
        pinMode(PIN_RESET, OUTPUT);
        pinMode(PIN_START, OUTPUT);
        pinMode(PIN_DRDY, INPUT);
        digitalWrite(PIN_CS, HIGH);
        digitalWrite(PIN_START, LOW);
        
        SPI.begin();
        SPI.setDataMode(SPI_MODE1);
        SPI.setClockDivider(SPI_CLOCK_DIV16);
        SPI.setBitOrder(MSBFIRST);
        delay(1000);
    
        digitalWrite(PIN_RESET, HIGH);
        delay(1000);
        digitalWrite(PIN_RESET, LOW);
        delay(1000);
        digitalWrite(PIN_RESET, HIGH);
        delay(100);  
    
        digitalWrite(PIN_CS, LOW);
        delay(1000);
        digitalWrite(PIN_CS, HIGH);
        delay(1000);    
    
    
        send_command(SDATAC);
        delay(10);
    
        for(;;)
        {
          uint8_t chSet = read_byte(READ | ID);
        
        Serial.print("-- ID" + String(chSet) + "--");
        delay(1000);
        }
    
    }
    
    
    
    
    void loop()
    {
    
        
    
    }

  • Hi Vindhyachal,

    You seem to have some extraneous chip select toggles (like the last one in your setup before the send_command (SDATAC)). That being said, are you getting the expected results from this code? Screen shots using a four channel scope (preferred, but a logic analyzer would also work) that show your chip select, MOSI, MISO and SCLK are an easier way for us to determine if your control signals to the ADS1298 are correct.