Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SRF08 & HCS12 I2C setup help

Status
Not open for further replies.

kestor

New Member
I am trying to get my HCS12 to communicate with an SRF08 I recently got ahold of. Specifically my uP board is a Adapt9S12DP256. On the SDA & SCL lines I have placed 4K7 pull ups, as I believe the pull ups in the HCS12 are too weak?? Anyway, the code I wrote to read & write reg's on the SRF08 doesn't seem to work. When I read reg 0 I am seeing a value of 8? Is this right? All other register are always 0, all the time? I am not sure if I am writing properly to the device either as if I attempt to re-program the SRF08 address to something other than 0xE0 then power cycle the SRF08 the LED should FLASH once plus a number of times depending on your offset from 0xE0, right? Mine flashes once always, meaning I am prob not writing to the device either. I know that there are some rather funky delays that need to be added between reg writes etc on the HCS12 side. Does anyone have any example C code that works for this hardware setup?

Cheers
 
Pull up

What do you mean the pull-ups are too weak? Perhaps I misunderstand but if you place another resistance in parallel with the "weak" pull-ups, you are reducing the resistance and making even more current flow?
 
I dont' know specifically about your uC, but on the PIC micro, the weak pull-ups are somewheres around 200kohm+, certainly not enough for I2c, provided they even work on your IO pins when the i2c module is active ... so placing 4.7k in parallel with that, the 4.7k will look like a short compared to the 200k ... in this example, you get about 4.5k, which should be fine.

with i2c the idea is to have a strong pull-up to Vdd, not a weak one ... 4.7k is the spec, but I've seen even 1k recommended in some cases.

anyway, with the I2C, can we see the code you're using? ... i2c is almost always a write before read ... you need to issue a write command with the read bit clear, and then another command with the read bit read set, and then read the bus to get the slaves reply

the datasheet for your gizmo claims the device behaves like a 24 series serial eeprom, so Nigels tutorials on eeproms would probably have some useful info, even with your uC being different.
 
dknguyen: Right, the internal uC pull ups on their own are too weak, i.e. the current flow to the positive rail is not "strong" enough therefore they are too "weak", placing the 4K7 in effective parallel produces a stronger pull to the positive rail by reducing the resistance, etc etc. I think.

4K7 is what was suggested to me, I also have 1K8, but that really might be too "strong" (almost a short).

justDIY: I think I have attached a section of the code, the read i2c function that I have pulled straight from the main file. The "shortdelay" function call literally produces a delay as indicated by its associated comment. The rest of the i2c_read function consists of reg writes and polled wait's, which you can see. I am hoping that something in here is wrong, otherwise I am really not sure what is going on.

Thanks again guys. :)
 

Attachments

  • I2C_test.c
    1.8 KB · Views: 425
Srf08

Well, I can't tell much without readingthe code yet. I can tell you that if you read regsiter 0 its always supposed to read the same number (the software revision number). Whether or not 8 is a valid software revision number, I don't know because I never bothered to read it with my SRF08.

And all othe registers are for the light sensor or distance, and all the distance registers would read 0 if you did not send a ranging command. I think the light sensor register (0x01?) should be reading a non-zero value based on light levels.
.shtml[/url]
 
Last edited:
Codw

I am really bad at reading someone else's code especially when its for a processor I have never used...so I am going to ask a few things as I go along. I am unfamilliar with these software commands you are using...

But it looks like you have the steps right for reading right. I can't really tell about the technical parts of the code that are unique to the processor.
 
Last edited:
Attached is a doc that I found from Intel and it describes how to determine your I2C pullups. I believe that it has a lot to do with how many devices are attached to the bus (AKA capacitve loading and the resultant transition speeds) and the length of the bus. 4.7K is usually fine.

I'm sure it is also described in the Philips I2C manual:

https://www.semiconductors.philips.com/acrobat_download/applicationnotes/AN10216_1.pdf


Rick
 

Attachments

  • bus design and pullup resistor calculation for i2c and smbus busses - smi2c_10.pdf
    42 KB · Views: 2,027
Status
Not open for further replies.

Latest threads

Back
Top