I have a problem incorporating the adc into my application.
When I run the AN00177_startKIT_adc_demo everything works as expected but not when I add it to my app.
Since the app is using i2c (I have made my own i2c_slave since the lib does not work yet) and it is a rather big app so I will focus on what works and when it not works.
This is how it is layed out on the cores:
Code: Select all
int main()
{
interface i2c_slave_callback_if i_i2c;
interface i2c_handler_if i_i2cHandler;
interface adc_handler_if i_adcHandler;
startkit_adc_if i_adc;
chan c_adc;
par {
on tile[0].core[1]: i2c_slave(i_i2c, p_scl, p_sda, SLAVE_ADDRESS, CLOCK_STRETCHING);
on tile[0].core[2]: i2c_handler(i_i2c, i_i2cHandler); //, p_dbg);
on tile[0].core[3]: handler_demon(i_i2cHandler, i_adcHandler); //, p_dbg);
on tile[0].core[4]: handler_adc(i_adcHandler, i_adc);
on tile[0].core[0]: adc_task(i_adc, c_adc, 0);
startkit_adc(c_adc);
}
return 0;
}
Code: Select all
#define LOOP_PERIOD 10000 // meassure adc val each 100 us
[[combinable]]
void handler_adc(client adc_handler_if sH, client startkit_adc_if i_adc)
{
timer t_loop;
uint32_t loop_time;
uint16_t adc_val[4] = {0, 0, 0, 0};
uint16_t counter = 0;
t_loop :> loop_time;
loop_time += LOOP_PERIOD;
while(1) {
select {
case t_loop when timerafter(loop_time) :> void:
//i_adc.trigger(); // When uncommented will bus.read_word_data(ADDR, 28) always return 0 sH.getADC(counter);
counter++;
sH.getADC(counter); // Inform handler about new value
// Add read of adc here
// i_adc.read(adc_val); // Get the values (and clear the notfication).
// If uncommented will bus.read_word_data(ADDR, 28) always return 1
loop_time += LOOP_PERIOD;
break;
// ########################################################################
// Read ADC upon completion (ADC is triggered every 100us)
case i_adc.complete(): //Notification from ADC server when aquisition complete
// i_adc.read(adc_val); //Get the values (and clear the notfication)
// sH.getADC(adc_val[0]);
// sH.getADC(counter);
break;
}
}
}
Note, bus.read_word_data(ADDR, 28) is the python command executed on my raspberry to read that counter value or rather the adc value once I get it to work.