Should I bitbang i2c ?

I’ve found in the https://github.com/beagleboard/am335x_pru_package/blob/master/am335xPruReferenceGuide.pdf at page 25 in the Constant Table the reference to i2c1 and i2c2, but I’ve not found a single code example of how to work with it.

Should i write the data in the 0x4802_A000 address, white a bit and read back the response from the i2c slave from 0x4802_A000 ?

Or trow all of this and take a GPIO and just bitbang ?

I stopped trying to utilize the i2c modules and just bitbanged it myself. If you need i2c bitbanging on the PRU, I can drop the link to the git for it tomorrow.

I’d be interested in i2c bitbang by the PRU!

regards, Michael

5Mhz I2C ? heh either way it sounds interesting!

I am eagerly awaiting your link :slight_smile:

Ti i2c master up 2 3.4Mbps

And with Bitbang ,what ever with ARM or PRU, I dont think you can get so high speed .

Here it is:
https://github.com/mcdonamp/RH_ROBO_Quadcopter/blob/master/i2c_bitbang/pru_sw/example_apps/control_alg/imu.p

I wrote it so we could communicate with an MPU6050 IMU via PRU for part of my senior design project. It’s a little rough, and was programmed with the MPU6050 in mind, and has been only tested with that IMU and a TMP101, so YMMV.
It supports single byte reads and single byte writes to addresses at a time. It doesn’t support reading multiple bytes, clock stretching, doesn’t really wait for an ACK, and I’m sure I ignored a few other features of i2c.

Take a look at conventions.hp as well. I made up my own conventions for calling the functions since I couldn’t find any established calling conventions for the PRU. The calling conventions are also documented (though slightly out of date, there are now more arg and ret val registers).

I checked our project’s wiki, and oddly I don’t see the PRU calling conventions documented there anymore. Here’s the jist of it:
–all registers are to be preserved upon exit from a functions (besides the retval registers)
–the stack grows downwards.

If you have any other questions about the code, feel free to ask!

Oh, and there is also bitbanged pwm in there as well, if you go up a directory. The files in control_alg are the ones being actively developed, and demonstrates a (rough) control algorithm for our quadcopter, which hasn’t actually flown yet. But it does show how to use the PWM and i2c PRU functions.

Hi, could you give me the link ? It’s not working anymore

Micka, ^^

https://github.com/Rose-Hulman-ROBO4xx/1314-BeagleBone-Quadcopter/tree/master_rev2/code/ControlAlgorithm/quadcopter_apps/imu

I based it off a PRU template, which is where the header is coming from. I am not that guy. I forgot to remove the header. :confused:
https://github.com/Rose-Hulman-ROBO4xx/1314-BeagleBone-Quadcopter/blob/master_rev2/code/ControlAlgorithm/quadcopter_apps/imu/imu.p

Did you get the link? Keep in mind that this code was purpose built to read data off of an MPU6051 IMU, iirc. So if you want to use it for your project it may require modification.

Yes thank you very much. I know and I will modify it. Thx for the code it is well done.

Micka,

Hey Mickae1, this might be useful to you: http://software-dl.ti.com/public/hpmp/sitara/debug_pru_using_ccs/index.html

That wasn’t available when I was working on my i2c code.

Hi guys,i was also working on how to bitbang i2c with pru.I used your code Christopher.My project was read sensor value from i2c1 on address 0x49 with sample rate 860,however i am always getting value as 0.00,i know i am making mistake while initilization,i was tryied so many times but i could not do it,Can you help me on how to assign sample rate value and read write!?Thanks in advance.

Hi again Mr. Christopher Hopwood ,i have changed your code,but i have some misunderstandings.How you assigned address,register,value.You have used 0xbb format,but i need 0xbbbb,is it possible in PRU?

Sorry Elaman, I've been kinda busy. Yeah, that should be possible. I
had just coded it to only use one byte of address when I was working
on the IMU6050. It should be a fairly simple change to make it use 2
bytes of address. May I ask, what device are you trying to talk to?

Sorry Elaman, I’ve been kinda busy. Yeah, that should be possible. I
had just coded it to only use one byte of address when I was working
on the IMU6050. It should be a fairly simple change to make it use 2
bytes of address. May I ask, what device are you trying to talk to?

Hi,

I am trying to toggle a GPO pin in mode GPIO using PRU.

For achieving this, I enable OCP master port and then write to GPIO_SETDATAOUT and GPIO_CLEARDATAOUT registers.
But, I can’t see any output on pin.

The pin is configured in 0x07 mode in device tree overlay.

Can you help me with this?

Thanks,
Anuja