Should I bitbang i2c ?

1,060 views
Skip to first unread message

Roy Bellingan

unread,
Sep 2, 2013, 2:57:29 AM9/2/13
to beagl...@googlegroups.com
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 ?

Christopher Hopwood

unread,
Oct 22, 2013, 1:10:17 AM10/22/13
to beagl...@googlegroups.com
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.

Michael Haberler

unread,
Dec 30, 2013, 5:32:26 AM12/30/13
to beagl...@googlegroups.com


On Tuesday, October 22, 2013 7:10:17 AM UTC+2, Christopher Hopwood wrote:
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 

William Hermans

unread,
Dec 30, 2013, 5:45:22 AM12/30/13
to beagl...@googlegroups.com
5Mhz I2C ? heh either way it sounds interesting!


--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Andrew Dai

unread,
Dec 30, 2013, 11:06:30 AM12/30/13
to beagl...@googlegroups.com
I am eagerly awaiting your link :)

liyaoshi

unread,
Dec 30, 2013, 8:58:02 PM12/30/13
to beagl...@googlegroups.com
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 .


2013/12/31 Andrew Dai <the...@andrewdai.co>
I am eagerly awaiting your link :)


On Tuesday, October 22, 2013 1:10:17 AM UTC-4, Christopher Hopwood wrote:
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.

--

Christopher Hopwood

unread,
Jan 1, 2014, 8:04:57 PM1/1/14
to beagl...@googlegroups.com
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).

Christopher Hopwood

unread,
Jan 1, 2014, 8:15:20 PM1/1/14
to beagl...@googlegroups.com
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!

Christopher Hopwood

unread,
Jan 1, 2014, 8:29:12 PM1/1/14
to beagl...@googlegroups.com
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.

Mickae1

unread,
Oct 2, 2015, 12:53:57 PM10/2/15
to BeagleBoard
Hi, could you give me the link ? It's not working anymore

Micka, ^^

Christopher Hopwood

unread,
Oct 2, 2015, 6:37:40 PM10/2/15
to BeagleBoard

Christopher Hopwood

unread,
Oct 2, 2015, 6:39:02 PM10/2/15
to BeagleBoard
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. :/
https://github.com/Rose-Hulman-ROBO4xx/1314-BeagleBone-Quadcopter/blob/master_rev2/code/ControlAlgorithm/quadcopter_apps/imu/imu.p

Christopher Hopwood

unread,
Oct 16, 2015, 12:02:55 PM10/16/15
to BeagleBoard
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.  


On Friday, October 2, 2015 at 11:53:57 AM UTC-5, Mickae1 wrote:

Micka

unread,
Oct 16, 2015, 1:06:17 PM10/16/15
to BeagleBoard

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

Micka,


--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Hopwood

unread,
Nov 16, 2015, 11:33:53 AM11/16/15
to BeagleBoard
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.

Elaman Nazarkulov

unread,
Dec 28, 2015, 9:21:10 AM12/28/15
to BeagleBoard, tsm...@gmail.com
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.

Elaman Nazarkulov

unread,
Jan 6, 2016, 3:14:25 AM1/6/16
to BeagleBoard
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?

Christopher Hopwood

unread,
Jan 11, 2016, 5:33:11 PM1/11/16
to beagl...@googlegroups.com
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?
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "BeagleBoard" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/beagleboard/_JfkFX-F3Ak/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Christopher Hopwood

unread,
Jan 11, 2016, 5:33:41 PM1/11/16
to BeagleBoard
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?

anujam...@gmail.com

unread,
Mar 23, 2016, 9:52:28 AM3/23/16
to BeagleBoard
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

Christopher Hopwood

unread,
Mar 23, 2016, 10:14:37 AM3/23/16
to BeagleBoard, anujam...@gmail.com
Hi Anuja,

Sorry, it has been a very long time since I last worked with the PRU.  I honestly don't remember.  Maybe some more googling around will help?

I got a fair bit of information from the elinux.org wiki.  I'm not sure what's right, but I would try getting that example working in the link above, and try to figure out what's different between your code and the example code that stops it from working.
Don't ignore search results with ECE497; it's the class ID for embedded linux at Rose-Hulman.  We worked with Beaglebones there.

Good luck!

emrek...@gmail.com

unread,
Jun 30, 2016, 9:25:11 AM6/30/16
to BeagleBoard, tsm...@gmail.com
I've always read a 0 value. Device beagleboneblack.I want to read data from i2c. i2c pins P9_17, P9_18, P9_19, P9_20. How can I do it. I would be glad if you can help. Thank you..

2 Eylül 2013 Pazartesi 09:57:29 UTC+3 tarihinde Roy Bellingan yazdı:
Ben buldum https://github.com/ / am335x_pru_ BeagleBoard paketi / leke / master / am335xPruReferenceGuide.pdf i2c2 Sabit tablo 25 de Referans, ama tek Bir kod Örneği buldum Değil A.Ş. sayfa i2c1 nasıl Ettik. Onunla çalışmak Için , Ben 0x4802_A000 adresinde beyaz biraz veri yazma 0x4802_A000 gelen i2c köle yanıtı geri Ettik okudunuz mu? meli Veya Tüm bu Almak İçin sadece sadece sadece sadece sadece sadece sadece sadece bitbang Ettik GPIO A.Ş. trow?





Reply all
Reply to author
Forward
0 new messages