GPIO ADC Slice on Slice Kit

If you have a simple question and just want an answer.
rmammina
Member
Posts: 9
Joined: Thu Mar 20, 2014 7:24 pm

GPIO ADC Slice on Slice Kit

Post by rmammina »

Hey I'm having troubles interfacing with the gpio adc slice using the slice kit. I can't seem to read a value from any of the ADC's on it.

I've interfaced the board with a simple potentiometer, and have tried just sending the 3.3v to the adc to read anything. There's a photo attached to this question regarding my understanding of the pinout for the adc on the gpio slice.

Here is the code I've been using (its a modification of the code used for simple gpio example).

Code: Select all

on stdcore[0]: struct r_i2c i2cOne = {
  XS1_PORT_1F,
  XS1_PORT_1F,
  1000
	};
 

void app_manager() {
  unsigned button_press_1,button_press_2,time,time1;
  int button =1,index=0,toggle=0;
  timer t;
  unsigned char data[1]={0x23};
  unsigned char data1[2];
  int adc_value;
  unsigned led_value=0x0E;
  
  p_PORT_BUT_1:> button_press_1;
  set_port_drive_low(p_PORT_BUT_1);
  
  //::Write config
  i2c_master_init(i2cOne);
  i2c_master_write_reg(0x28, 0x00, data, 1, i2cOne); //Write configuration information to ADC
  
  //::Config
  t:>time;
  
  printstrln("** WELCOME TO SIMPLE GPIO DEMO **");
  while(1) {
    //::Select start
    select {
      case button => p_PORT_BUT_1 when pinsneq(button_press_1):> button_press_1: //checks if any button is pressed
        button=0;
        t:>time;
        break;
      
      //waits for 20ms and checks if the same button is pressed or not
      case !button => t when timerafter(time+debounce_time):>void:
        p_PORT_BUT_1:> button_press_2;
        if(button_press_1==button_press_2)
        //Button 1 is pressed
        if(button_press_1 == BUTTON_PRESS_VALUE)  {
           printstrln("Button 1 Pressed");
           p_led<:(led_value);
           led_value=led_value<<1;
           led_value|=0x01;
           led_value=led_value & 0x0F;
           if(led_value == 15){
           led_value=0x0E;
         }
       }
       
       //Button 2 is pressed
       if(button_press_1 == BUTTON_PRESS_VALUE-1) {
          data1[0]=0;data1[1]=0;
          
          //Read ADC value using I2C read
          i2c_master_rx(0x29, data1, 2, i2cOne); 
          
          data1[0]=data1[0]&0x0F;
          adc_value=(data1[0]<<6)|(data1[1]>>2);
          
          printstr("Value is: ");
          printintln(adc_value);
       }
       button=1;
       break;
      }
   }
}
 

int main(void) {
   par {
      on stdcore[0]: app_manager();
   }
return 0;
}
I consistently get the output of 
value: 0
value: 0
 
I tried to check each element of data1, but those are both 0 after reading from adc.
 
Any help would be great.
 
Thanks!
You do not have the required permissions to view the files attached to this post.


User avatar
yuvaraj
Member
Posts: 8
Joined: Fri Oct 18, 2013 9:23 am

Post by yuvaraj »

Hai,

What i2c module you are using?

On your code, I found both sda and scl lines are mapped to same GPIO "XS1_PORT_1F"

if you are using module_i2c_master, then structure r_i2c has the following elements in it.

typedef struct r_i2c {
    port scl;      /**< Port on which clock wire is attached. Must be on bit 0 */
    port sda;      /**< Port on which data wire is attached. Must be on bit 0 */
    unsigned int clockTicks; /**< Number of reference clocks per I2C clock,
                              *   set to 1000 for 100 Khz. */
}  r_i2c;

So your code should have something like,

struct r_i2c i2cOne = {
    XS1_PORT_1F,
    XS1_PORT_1B,
    1000,
};

Also there is no need to change the slave address to 0x29 while doing "i2c_master_rx". The function itself adds the READBit.

Hope this could resolve your problem.