It looks like you're new here. If you want to get involved, click one of these buttons!
I am trying to communicate an arduino master using I2C to read ADC values of a slave.
When the master sends some data ( i.e 0x20 for ADC register1) an interupt service routine (Combuf_isr) is run which is supposed to interpret this data (know that I want to read adc register), then read the adc register and then write the adc values so that the master can read them.
I would like to have it so that the adc values are periodically updated and the master can just send read maybe every 100ms.
I am new to C so I can only come up with something like the code below but problem is I do not think it updates the adc values periodically and also I have got 2 ADC registers so in the main function how do I make it so that it runs the ISR if the COM_DIF_TO_MCU receives either 0x20 or 0x23.
/* do some housekeeping stuff, e.g. clear ISR bit /
int cmd = COM_DIF_TO_MCU_read(); / read COMBUF data */
int res = -100;
/* process COMBUF data /
/ you chose 0x20 to represent ADC reading PADC_DATA1 register */
res = readPADC_DATA1reg();
/* you chose 0x23 to represent ADC reading PADC_DATA3 register */ case 0x23: res = readPADC_DATA3reg(); break; default: /* the cmd is invalid, so -1 will be returned */ break; } COM_MCU_TO_DIF_write(res);