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;
}
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!