i2c problem

klaasje

Member
Hi

I have problem with the 40x2. When i send to a slave (20x2) it works fine, but when i put a adcsetup in the program the i2c stops. (seen on oscilloscope) Did a simple test.


#picaxe 40x2

hi2csetup i2cmaster, %10000000, i2cfast, i2cbyte
pause 2000
do

'adcsetup = 19

pause 100
hi2cout[ 2],2,(b1)
pause 10
inc b1
debug
loop

#picaxe 20x2
'set I2C protocol
pause 300
hi2csetup i2cslave,2
pause 100


do

pause 100
get 2,b0
pause 200


inc b2

debug
loop

#picaxe 20x2
'set I2C protocol
pause 300
hi2csetup i2cslave,2
pause 100


do

pause 100
get 2,b0
pause 200


inc b2

debug
loop

this works. But if i want to use the adcsetup the i2c bus stops working.

What am i doing wrong?

Thanks
 

hippy

Technical Support
Staff member
"ADCSETUP = 19", where 19 is %10011, will be setting ADC4, ADC1 and ADC0 as analogue input pins.

ADC4 is pin C.3 which is also I2C SCL so setting that to analogue is possibly causing it to stop working as I2C SCL.

Try with "ADCSETUP = 3" to see if that works.
 

klaasje

Member
Hi Hippy

It starts running again. But i must read ADC18 and ADC19. Now he is only reading ADC18. What do i do in the setup then?
Is it anywhere in the manual?

Thanks
 

inglewoodpete

Senior Member
Correct. ADCSetUp and ADCSetUp2 commands expect a bit pattern to reference the ADC channels. As described in the command descriptions, each bit refers to an ADC channel. So bit 0 of ADCSetUp points to ADC0 .... and bit 3 of ADCSetUp2 points to ADC19.

As hippy says, you can reference several pins at once in the ADCSetUp/ADCSetUp2 commands but it can be confusing. It is easiest to use a binary number to reference the inputs you want to be ADC inputs.
 

klaasje

Member
I think you mean that you can only work with readadc10 command.
But that did not work well.
ADC reading failed sometimes or ic2 fails.

With the masking it works stable.

Thanks all for the help
 
Top