PDA

View Full Version : Still new to PicBasic - i2c questions



cometboy
- 10th November 2006, 19:17
Thanks for getting me started on the LED blinking, finding out about the POKE command for setting the correct clock rate was a big thing for me.

I'm using the i2cout command at this time and have a few questions.

1) the command seems to work for some PICs but not others. I get a compiler error - undefined symbol PortA for a 12F629, but not for a 16F819.

Is this a correct diagnosis?

2) What kind of preliminary housekeeping commands would I need to set up the 16F819 for i2c operation. I'm sure that I have to set the clock rate (4MHz) and the PortA,0 and PortA,1 as outputs, but anything else?

3) The command i2cout has me a little confused. The first variable is the control code, with the leading bite determining the address as word or byte. The next variable contains the i2c device address.

I am going to be talking to a PCA9633 PWM LED driver. Theis device has no control code, only a slave address. Once the slave answers the address byte, you start feeding it data to set the LEDs.

I have sucessfully run this device using another PIC device, the PicAxe, from England. The data sequence was ADDRESS,DATA,DATA... with no control code.

I'm sure a lot of this is pretty inchoherent, but I'm just learning how to ask questions in PBC. I'm also working on this in parallel, so might find the answers myself. But your last answer really helped, so here I am.

Thanks.

Alan

sayzer
- 10th November 2006, 20:04
Let me take number 1.


...

1) ...I get a compiler error - undefined symbol PortA for a 12F629, but not for a 16F819.

Is this a correct diagnosis?...

Alan


Alan,

Check the datasheet of 12F629.
You will see that the PORTA does not exist.
You will see GPIO.

PORTA is valid for 16F819. TRISA is also.
You get these as GPIO and TRISIO for 12F629.



------------------------------

SteveB
- 10th November 2006, 20:22
I'll take #3:

The example in the PicBasic manual assumes an I2C EEPROM. So, it uses the word "control" for the device address, and "address" is the memory address inside the EEPROM. So, in your case, I would try it using the following construct:

I2COUT address, data1, (data2, ....)

HTH
Steve

cometboy
- 13th November 2006, 18:14
I'm still getting no joy from the i2c command. I'm using a PIC16F819 chip with the following program.

Using a scope on PortA,0 and 1, I see no modulation on either line. The two lines stay high from the 10Kohm pullup resistors on the slave device.

poke $8F,%01100000 'set oscillator to 4MHz - OSCCON
poke $03,%00110000 'set to Bank 1 - STATUS
poke $85,%00000000 'set PortA all outputs - TRISA
symbol addr = %00101010
symbol blah = $80
main:
i2cout addr,blah,($00,%0000100,255,0,0,%10000000,$FF,$00, %10101010)
pause 100
goto main

Any clues? Thanks for the previous comments.

Alan

mister_e
- 13th November 2006, 18:27
first observation, you forgot to disable the analog stuff on those Pins.

POKE $9F,7

And i think PBC handle the bank switch for you... i think.