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
History
Below, there is a bunch of attempts I've made learning some I2C. You can also find some useful links.