Click here to Skip to main content
13,146,742 members (80,045 online)
Click here to Skip to main content
Add your own
alternative version

Stats

4K views
4 bookmarked
Posted 11 May 2016

I2C Between Raspberry and Pic24

, 11 May 2016
Rate this:
Please Sign up or sign in to vote.
RaspberryPi2 master transmits to and receives from Pic24FJ64GB002 slave through I2C

Default I2C bus frequency: 100kHz. RaspberryPi2 has I2C module activated. Pic24 Is mounted on Microstick II.

Pic24: Ra0, Ra1 and Ra2 are outputs for 3 Leds.

3 I2C wires between RaspberryPi2 and Pic24: Gpio3->Microchip18; Gpio5->Microchip17; Gpio9->Microchip27. The length of 3 wires is 20 cm.

I2Cms Random

I trimmed the delay code at the head of _SI2C1Interrupt in Pic24. Too long and it slows everything down and also makes errors.

Using the code: Raspberry fills a table with 256 random numbers [0, 255], sends it to Pic24. Pic24 receives and sends back the table. Raspberry compares local and received table.

Load I2Cs6.X on Pic24 and I2Cm5 on Raspberry. Type sudo ./I2Cm or sudo ./I2Cm xxx . xxx must be a positive number: number of cycles desired: 800 for example.

 

I2Cms Ranges

I trimmed the delay code at the head of _SI2C1Interrupt in Pic24. This time, I used some more delay.

Using the code: Raspberry sends Pic24 3 parameters: start number, number of iterations, increment. Pic24 increments start number for number of iterations and sends back all numbers calculated. These numbers are compared with local copies in Raspberry.

Load I2Cs7.X on Pic24 and I2Cm6 on Raspberry. Type sudo ./I2Cm xxx yyy zzz. xxx, yyy, zzz must be numbers in the range [0,255]. All parameters are needed. Now Raspberry can send commands to Pic24. Heap on Pic24 wasn't strictly necessary, but it helps. There isn't a 1 to 1 dependency between dimension of array and heap needed. In this case, my max dimension would be 255 elements, but Pic24 wants more or less 500. I don't intervene in the overflow that Rx and Tx registers of Pic24 have for I2C: they correctly manage only 8 bits. The digits displayed by PuTTY are correct.

I use VisualGDB to program Raspberry from laptop ASUS with Windows10; MPLAB X IDE v 3.20 for Pic24.

Points of Interest

  • I2C

History

Below, there is a bunch of attempts I've made learning some I2C. You can also find some useful links.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 11 May 2016
Article Copyright 2016 by Member 11246861
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid