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.

Urgent please >> ADS1248 read out data problems?

Other Parts Discussed in Thread: ADS1248

Dear all,

i'm trying to communicate with the ADS1248 by writing one register and read it again, i'd like to know what is the code that i read in read operation is it 8bit as per data sheet or two's compliment of my stored register data?

this code written by CODE Vision AVR tool

 

  conv_en=1;     //start goes high
  spi_en=0;        //spi enable low
  spi(16);            //SDATAC command
  spi_en=1;
  delay_ms(2000);

while (1)
      {
      // Place your code here

     spi_en=0;
     spi(0x4B);   //write ot IDAC1
     spi(0x00);
     spi(255);
     spi_en=1;

     spi_en=0;
     spi(0x2B);    //read IDAC1
     spi(0x00);
     x=(signed)spi(0xFF)<<8;
     spi_en=1;
     
  sprintf(lcd_buf,"%03d",x); //display IDAC1 value on lcd
  lcd_gotoxy(5,0);
  lcd_puts(lcd_buf); 

        
      };

  • Dear all,

    i'm trying to communicate with the ADS1248 by writing one register and read it again, i'd like to know what is the code that i read in read operation is it 8bit as per data sheet or two's compliment of my stored register data?

     

     


    Chip type           : ATmega16
    Program type        : Application
    Clock frequency     : 4.000000 MHz
    Memory model        : Small
    External SRAM size  : 0
    Data Stack size     : 256
    *****************************************************/

    #include <mega16.h>
    #include <delay.h>
    #include <stdio.h>

    // Alphanumeric LCD Module functions
    #asm
       .equ __lcd_port=0x1B ;PORTA
    #endasm
    #include <lcd.h>

    // SPI functions
    #include <spi.h>
    #define   mux0     0x00
    #define   vbias    0x01     
    #define   mux1     0x02    
    #define   sys0     0x03    
    #define   ofc0     0x04    
    #define   ofc1     0x05    
    #define   ofc2     0x06    
    #define   fsc0     0x07    
    #define   fsc1     0x08    
    #define   fsc2     0x09    
    #define   idac0    0x0A    
    #define   idac1    0x0B    
    #define   gpiocfg  0x0C    
    #define   gpoidir  0x0D    
    #define   gpiodat  0x0E    
    #define   spi_en   PORTD.0    
    #define   conv_en  PORTD.1    
    #define   spi_rst  PORTD.2
    #define   drdy     PORTD.4

    // Declare your global variables here
    // Declare your global variables here
    unsigned int ad,z,percentage,k,div[3],mamp_out,step,delay;
    char lcd_buf[30],start,digit,i,z1,q,q1,prg,middel,jump1,ma,tap,current;
    char old_step,program,var1,var2,var3,open,data,data_old;
    unsigned long int  temp;
    signed int x;
    void display(unsigned int y);       //Seven segment display function
    void temp_read(unsigned long int data);       //bar graph display function

    void main(void)
    {
    // Declare your local variables here

    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    PORTA=0x00;
    DDRA=0x00;

    // Port B initialization
    // Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
    // State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
    PORTB=0x00;
    DDRB=0xB0;

    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
    PORTC=0x00;
    DDRC=0x00;

    // Port D initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out
    // State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=0
    PORTD=0x00;
    DDRD=0x07;

    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: Timer 0 Stopped
    // Mode: Normal top=FFh
    // OC0 output: Disconnected
    TCCR0=0x00;
    TCNT0=0x00;
    OCR0=0x00;

    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: Timer 1 Stopped
    // Mode: Normal top=FFFFh
    // OC1A output: Discon.
    // OC1B output: Discon.
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    TCCR1A=0x00;
    TCCR1B=0x00;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;

    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer 2 Stopped
    // Mode: Normal top=FFh
    // OC2 output: Disconnected
    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;

    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=0x00;
    MCUCSR=0x00;

    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x00;

    // Analog Comparator initialization
    // Analog Comparator: Off
    // Analog Comparator Input Capture by Timer/Counter 1: Off
    ACSR=0x80;
    SFIOR=0x00;

    // SPI initialization
    // SPI Type: Master
    // SPI Clock Rate: 31.250 kHz
    // SPI Clock Phase: Cycle Half
    // SPI Clock Polarity: Low
    // SPI Data Order: MSB First
    SPCR=0x53;
    SPSR=0x00;

    // LCD module initialization
    lcd_init(16);
    x=55;
      sprintf(lcd_buf,"%02d",x);
      lcd_gotoxy(10,1);
      lcd_puts(lcd_buf); 


      conv_en=1;     //start goes high
      spi_en=0;      //spi enable low
      spi(16);       //SDATAC command
      spi_en=1;
      delay_ms(2000);

    while (1)
          {
          // Place your code here

         spi_en=0;
         spi(0x4B);   //write ot IDAC1
         spi(0x00);
         spi(255);
         spi_en=1;

         spi_en=0;
         spi(0x2B);
         spi(0x00);
         x=(signed)spi(0xFF)<<8;
         spi_en=1;
         
      sprintf(lcd_buf,"%03d",x);
      lcd_gotoxy(5,0);
      lcd_puts(lcd_buf); 


      sprintf(lcd_buf,"%03d",q);
      lcd_gotoxy(2,1);
      lcd_puts(lcd_buf); 
     
            
          };
    }

  • Hi Mahmoud, I am not familiar with the ATmega processors or their code tools, but the registers in the ADS1248 are 8-bits in length. The conversion data is binary twos complement. What does your code snippet above return?
  • Hi Tom,

    my sequence of operation as follow:

    1-Enable start bit "high".

    2-send SDATAC command and wait 2sec for system mode change

      spi_en=0;       //spi enable low
      spi(16);            //SDATAC command
      spi_en=1;        //spi disable high

    3-send WREG command and write in IDAC1

         spi_en=0;       //spi enable low
         spi(0x4B);       //write to IDAC1 address
         spi(0x00);       //number of bytes to be written -1
         spi(0xFF);       //sent data to IDAC1 register " write 0xFF hex in it"
         spi_en=1;      //spi disable high

    4-  read sent data

        spi_en=0;       //spi enable low
         spi(0x2B);       //read IDAC1 command address
         spi(0x00);       //number of bytes to be written -1
         x=(signed)spi(0xFF)<<8;   //send NOP command during data receiving and read one byte
         spi_en=1;         //spi disable high

    5-x value defined as singed int.

    6-i get returned value is 32512 is it the two's compliment of 0xFF hex?

  • Hi Mohammed,

    When reading the registers you should be able to read straight binary (one -byte) FFh. (1111 1111)

    3-send WREG command and write in IDAC1

         spi_en=0;       //spi enable low
         spi(0x4B);       //write to IDAC1 address
         spi(0x00);       //number of bytes to be written -1
         spi(0xFF);       //sent data to IDAC1 register " write 0xFF hex in it"
     
        spi_en=1;      //spi disable high

    4-  read sent data

        spi_en=0;       //spi enable low
         spi(0x2B);       //read IDAC1 command address
         spi(0x00);       //number of bytes to be written -1
         x=(signed)spi(0xFF)<<8;   //send NOP command during data receiving and read one byte
         spi_en=1;         //spi disable high

    Can you confirm with the oscilloscope what you are writting/reading during these two sequences?  Please provide oscilloscope plots for the DI, DOUT, CS, SCLK During the WREG and RREG commands.

    Thank you and Kind Regards,

    Luis

     

  • hi Luis,

    1-this is plot include DI vs SCLK during WREG command

     

    2-CS vs SCLK during WREG

     

     

     

     

     

     

    replay me back

  • Hello Mahmoud,

    Please find two examples attached with oscilloscope plots:

    Holding the Start pin high, after issuing a SDATAC command:

    WREG IDAC1 FFh: 4B00FF and RREG IDAC1 2B00:  Reads back FF: Plots1 and 2

    WREG IDAC1 11h: 4B0011 and RREG IDAC1 2B00: Reads back 11: Plots 3 and 4

    I have acouple of questions: 

    Are you holding the Start pin high?

    How does the result on the oscilloscope you provided translates to 32512?

    Thank you and Regards,

     Luis

     

    Plot1: CH1:CS, CH2:SCLK, CH3: DIN, CH4: DOUT

    Plot2

     

    Plot3

     

    Plot4

  • Hi Mahmoud,

    Another suggestion, it appears that in your code you may be shifting the reading by 8:

    4-  read sent data

        spi_en=0;       //spi enable low
         spi(0x2B);       //read IDAC1 command address
         spi(0x00);       //number of bytes to be written -1
         x=(signed)spi(0xFF)<<8;   //send NOP command during data receiving and read one byte
         spi_en=1;         //spi disable high

    So it appears that the reading may be stored in memory as 0xFF00 instead of 0x00FF.  Can you try it again by erasing the "<<8" on your code? 

    Please let me know if this helps,

    Thanks!

    Luis

  • hi Luis,

    i've  tried your suggestion by removing shift lift command and i got data as following:

    1-writing 0xFF "255dec" result in reading output 0x7F "127 decimal"             2-writing 0x0F "15dec" result in reading output 0x07 "7 decimal" 

    3-writing 0x30 "48dec" result in reading output 0x18 "24 decimal"                  4-writing 0x27 "39dec" result in reading output 0x13 "19 decimal".

    and so on, my question is why first "least significant" bit not appeared and how to solve it? is this due to singed data returned from ADS1248 or not?

    note:i've tried to change x value definition from singed int to unsigned int but no effect.

     

    Another question, the ADS1248 registers has some bits that are read only what happens to those bits when i send data to their registers that include writing 0 or 1 to those bits?

    many thanks

    Mahmoud

  • Hello Mahmoud,

    Can you experiment changing the  SPI settings  (Clock phase)?   This may solve the problem. 

    CPHA=0

    CPOL=0

    Please let me know if it solves the problem

    Thank you and Kind Regards,

    Luis

    //SPI initialization
    // SPI Type: Master
    // SPI Clock Rate: 31.250 kHz
    // SPI Clock Phase: Cycle Half   ==>Change this to CPHA=0
    // SPI Data Order: MSB First
    SPCR=0x53;
    SPSR=0x00;

  • Hi Luis,

    your suggestion work very good, now i can read my written data.

    BUT what about >>>

    the ADS1248 registers has some bits that are read only what happens to those bits when i send data to their registers that include writing 0 or 1 to those bits?

    i've configured the ADS1248 registers as following :

         spi_en=0;
         spi(0x42);   //write ot MUX1&SYS0
         spi(0x01);  
         spi(0x20);   //MUX1=32
         spi(0x02);   //SYS0=2
         spi_en=1;

         spi_en=0;
         spi(0x4A);
         spi(0x01);
         spi(0x06);   //IDAC0=6    set i magnitude to 1mAmp
         spi(0x01);   //IDAC1=1    connect IEXC1 TO AIN0 & connect IEXC2 TO AIN1
         spi_en=1;

    and i have read them OK but no mAmp current follow from AIN0 neither AIN1 to GND

    please help me.

    many thanks,

    Mahmoud

     

  • Hi Luis,

    the ADS1248 registers has some bits that are read only what happens to those bits when i send data to their own registers that include writing 0 or 1 to those bits?

    also, i've configured the ADS1248 registers as following :

         spi_en=0;
         spi(0x42);   //write to MUX1&SYS0
         spi(0x01);  
         spi(0x20);   //MUX1=32
         spi(0x02);   //SYS0=2
         spi_en=1;

         spi_en=0;
         spi(0x4A);
         spi(0x01);
         spi(0x06);   //IDAC0=6    set i magnitude to 1mAmp
         spi(0x01);   //IDAC1=1    connect IEXC1 TO AIN0 & connect IEXC2 TO AIN1
         spi_en=1;

    and i have read them back OK but, no mAmp current follow from AIN0 neither AIN1 to GND

    please help me.

    Mahmoud

  • Hello Mahmoud,

    You have submitted this question in a separate post.  Please find a reply to this question in your "ADS1248 no mA" post.

    Thank you and Regards,

    Luis