PDA

View Full Version : SPo3 and I2C



fatboylives
- 22nd January 2005, 21:40
Hi all.

I need what might be some basic help with some I2C code.

I have a SP03 module and the I2C specs for that are on http://www.robot-electronics.co.uk/htm/Sp03doc.shtml
I am using a 16f877 with 20 mhz crystal. Basically for now I need to read the command status? Can anyone offer a suggestion? Also are the pins I have selected to use for Data and Clock ok on the 877 or should I be using specific pins? Do they need pull up resistors? I have tried different varioations of code and can't get a response....


My code

DEFINE OSC 20
define i2c_slow 1' Tried this as a test


Wdog Var Portb.7
DPIN var PORTB.6 ' I2C data pin
CPIN var PORTB.5 ' I2C clock pin
talk var portd.2 ' Indicate still busy
NOP CON 0
B1 var byte


High talk 'Unit talks on power up. So indicate
loop:
Toggle wdog
pause 200
I2CREAD DPIN,CPIN,$C4,[B1] 'Read if still talking

if b1 > 0 then goto loop
low talk
goto loop

mister_e
- 22nd January 2005, 22:13
Also are the pins I have selected to use for Data and Clock ok on the 877 or should I be using specific pins? Do they need pull up resistors?

Your selected pins are O.K. Yes you need external Pull-ups ... 4.7K is a common used value.

fatboylives
- 22nd January 2005, 22:43
Thanks for the help so far. I will give it a go.

Do I also need the define i2c_slow 1? I read the manual as it is needed if speed is over 4 megs so I take it as yes?

mister_e
- 22nd January 2005, 22:53
Hi fatboylives, They say they test it over 1MHZ I2C clock so you don't need the define. In PBP I2c SLOW is 100KHZ when not 400KHZ

fatboylives
- 22nd January 2005, 23:20
What happened to your previous post. When I logged in to read your reply re the Define part, I went back to read your earlier post and grab the code and there is none there? I can only see the


quote:
--------------------------------------------------------------------------------

Also are the pins I have selected to use for Data and Clock ok on the 877 or should I be using specific pins? Do they need pull up resistors?
--------------------------------------------------------------------------------



Your selected pins are O.K. Yes you need external Pull-ups ... 4.7K is a common used value.




part. The code you provided has vanished....

Does this happen or am I just over tired?

mister_e
- 22nd January 2005, 23:29
Nop, i remove the code myself. I was really not sure of the way we have to talk to this module. Info are not so clear... maybe i'm a pure idiot and over-tired myself too.

I see different way to access. So i bet we can read from control register like

ModuleAddress = $C5
CommandRegister = 0
I2CREAD DPIN,CPIN,ModuleAddress,CommandRegister,[B1]

mister_e
- 22nd January 2005, 23:50
or

ModuleAddress = $C4
CommandRegister = 0
I2CWRITE DPIN,CPIN,ModuleAddress,[CommandRegister]

ModuleAddress = $C5
I2CREAD DPIN,CPIN,ModuleAddress,[b1]

i don't know :-(

fatboylives
- 23rd January 2005, 00:42
Is there any reason your example shows moduleaddress as $C4 on the write and $C5 on the read? Shouldn't they be the same.

I might have to use serial instead of I2C if I cannot get it to work...

Currently I get various values returned and nothi9ng makes sense....... Not unusual for me :-)