1

I have a Pi B+ on which I'm trying to bit-bash an I2C Slave in C / C++ (code's pretty much C despite the fact I'm using g++ and .cpp files), utilizing GPIO 18 as my Clock and GPIO 17 as my Data. I'm utilizing the BCM2835 C library from Mike M. My code is a little less featured that a true Slave, if only because I don't expect to be sending information back to the Master.

To test my code, I've used the Pi's built-in I2C Master bus, as well as a RasPi 2's Master Bus. Both utilized the BCM2835 library's native functions to communicate with the PI B+ Slave code. And from both I find that the Pi recognizes that the Master on the bus is trying to communicate with Slave 0x00.

I've checked the clock and data lines with an oscilloscope, and I see for certain that it's sending 11001100 - address 0x66, write. I've coded the Slave to respond to 0x66, but it doesn't seem to see the data at all.

I know for certain that the Pi is seeing the clock - debugging output displays that a message was sent to 0x00 after 8 bits on the clock - but for some reason it doesn't see the data. A separate pin test I've run, wiring the 3v3 pin direct to my Data pin, indicates it's reading as intended.

My question for you all is this: what would I need to do to get my code to recognize information flowing in through my data pin? Here's my code, if that's something you'd like to look over. This isn't the full code - I start a thread in main to initialize this function, and then I listen for a keypress on q to turn alive to false.


Edit 1:
Because I've got a B+, I'm currently investigating using the BSC module the BCM2835 has in it. Supposedly it can be used as an I2C Slave. While it's not implemented for access in Mike M's code, I can still use his code to get at the base registers.

  • The master Pi is using I2C bus 1 on gpios 2/3. The master is using the standard I2C driver operating at 100kbps. The separate slave Pi is bit banged using gpios 17/18. Is that correct as far as it goes? – joan Mar 27 '15 at 16:42
  • That is correct. I've also made sure that the grounds of the two devices are connected (had a bit of an issue with the slave receiving ~500 messages to 0x00 despite the other side being unpowered). – sctjkc01 Mar 27 '15 at 16:44
  • My initial feeling is that you are being too ambitious. Try slowing the clock down to something like 10kbps for testing. Your process is going to be scheduled out every now and then. Neither does the Pi support clock stretching as a master. – joan Mar 27 '15 at 16:52
  • @joan I've already tried setting the master's clock as low as I can make it - I've tried using bcm2835_i2c_set_baudrate(1000) - deets - to no avail; the oscilloscope said I was spitting out at roughly 10 kbps. It might be because I'm using an already-established I2C Master to test this, it might be messing with the results. The only alternative is to bit-bang a master as well, which seems rather pointless. – sctjkc01 Mar 27 '15 at 16:56
  • Ok, the other odd thing is in the code you test against 0x66 rather than 0xCC. I assumed you were shifting down one somewhere for the address, perhaps you aren't. – joan Mar 27 '15 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.