GPIO ADC Slice on Slice Kit

New to XMOS and XCore? Get started here.
Post Reply
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).

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: 0value: 0 I tried to check each element of data1, but those are both 0 after reading from adc. Any help would be great. Thanks!Read


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

Code: Select all

on stdcore[0]: struct r_i2c i2cOne = {
  XS1_PORT_1F,
  XS1_PORT_1F,
  1000
};
These two ports cannot be the same

I tried to edit your post to put the code between code tags, somehow all the new lines disappeared. Can you please repost your code using

Code: Select all

 [/code ] tags?
I'm really sorry for the inconvenience.
rmammina
Member
Posts: 9
Joined: Thu Mar 20, 2014 7:24 pm

Post by rmammina »

Yeah, I was trying to post through Q&A link. I'll repost here. Also, that was a typo for the port mappings.

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.

Image

I've interfaced the board with a simple potentiometer, and have tried just sending the 3.3v to the adc to read anything. The photo above is 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_1B,

  1000
};

Code: Select all

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(0x28, 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;

      }

   }

}

Code: Select all

int main(void) {

   par {

      on stdcore[0]: app_manager();

   }

return 0;

}
User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

I noticed you are using the Star slot, and the XMOS-link switch on the XTAG adapter is set to the On position.

From the SliceKit Hardware Manual:
The only complication in this system is use of the XScope 2-bit XMOS Link. This
link overlaps a 4 bit port on the Star Slot connector so it would not be possible to
use this for user IO at the same time as XScope.
To work around this, a switch is present on the XSYS adapter board to either enable
or disable the XScope XMOS Link. When disabled, these pins are disconnected from
the Chain Connector and are free for use on the Star Slot. When enabled they will
work as an XMOS link and hence will appear on the relevant pins of the Star Slot.
It is recommended that if a Slice Card is used in the Star Slot the XScope switch is
off on the XSYS Adaptor Card to ensure correct operation of the Slice Card in the
Star slot.
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Does the Temperature Demo code work (as supplied by XMOS) ?

Please try and post your status. If the temperature demo does work then please share your wiring for the potentiometer. If the temperature demo does not work then perhaps the I2C device is not being accessed. We recall testing the sample code and it did work as supplied.

So for your potentiometer, you have it wired like this ?

Lead # 1 = +3.3 volts
Lead # 2 (middle) = to your ADC
Lead # 3 = Ground


What is the resistance of your potentiometer ?

What are the values you are reading with your setup ? - never mind - you posted this earlier.

If the photo is current, you are using only 2 legs of the potentiometer ? The GROUND appears to be missing (at least from the photo). The GROUND wire is required to create the voltage divider effect using the potentiometer.
rmammina
Member
Posts: 9
Joined: Thu Mar 20, 2014 7:24 pm

Post by rmammina »

I got it working. I re-downloaded the source code and tried it on the square tile.

However, when I try to get it working on the star tile, the adc value just shows up as 0. I tried turning off the switch, but that didn't fix it.
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Glad to hear you have had some success.

When you use the SQUARE slot, you are bonded to Tile 1. I2C is a direct connect to 1F and 1B via slot pins A15 and A8.

So, I2C mappings for SQUARE slot are:

I2C_SCL = PCIe pin A15 = Port_1F on Tile 1
I2C_SDA = PCIe pin A8 = Port_1B on Tile 1

and I2C mappings for STAR slot are:

I2C_SCL = PCIe pin A15 = Port_1F on Tile 0
I2C_SDA = PCIe pin A8 = Port_1B on Tile 0

However, upon a review of the Slicekit Schematics 1v2

https://www.xmos.com/support/downloads/ ... nent=16282

the SQUARE slot port pins are directly connected to the XMOS processor for Port_1F (A15) and Port_1B (A8).

Yet on the STAR slot, the Port_1F (A15) is directly connected to the XMOS processor but Port_1B (A8) is NOT. Port_1B (on STAR slot) is connected to a mux that is sharing the same pins for SPI Flash boot / use.

Specifically, PCIe A8 (STAR slot) is connected to pin 5 of U6 (74CBTLV3257)(X0D1_EXT). Therefore, you will need to incorporate into your source code a small write to the port pin that will switch the mux for your usage. Be sure to use the latest documentation posted here:

http://www.xcore.com/forum/viewtopic.ph ... hilit=mon2

You will need to jiggy with ports X0D42 and X0D43 to flip the MUX's S pin in your favour.

Post back if you need the specific few lines of code required to switch the mux. Have it at the office. Likely this was the issue all along for your STAR slot use.

Kumar
Post Reply