chipKIT® Development Platform

Inspired by Arduino™

How to address the I2C ports on WF32

Created Fri, 02 May 2014 10:29:14 +0000 by samdesd


samdesd

Fri, 02 May 2014 10:29:14 +0000

Hi,

There are few I2C ports on WF32 (PIC32MX695) board. Can someone please clarify how the I2C port numbering works? Specifically, pin 45,46 (Chipkit numbers)... what should I call it in Arduino style programming?

Any specific reference on all these little little things about associating the port name "Arduino ways" for PIC32? Life can be made much simpler!

NOTE: For UART, there are Serial, Serial0, Serial1, etc

Thanks

SAM


majenko

Fri, 02 May 2014 11:34:30 +0000

At the moment it is only possible to reference one I2C port through the Wire library. There has been planned for some time now a DTWI library which would be the I2C equivalent of the DSPI library for SPI. It is supposed to allow access to multiple I2C busses, however it hasn't actually been written yet.

Bit of a pain really.


samdesd

Fri, 02 May 2014 12:44:52 +0000

Hi majenko, What would be the way out...use p32xxxx.h and write conventionally like in mplab? This wire refers to which i2c...on chipkit pin? Does this also applies to spi port? Thanks. Sam


majenko

Fri, 02 May 2014 13:00:03 +0000

The Wire library refers to the port pointed to by the TWI* defines in the board variant files (Board_Defs.h).

I have just been looking at expanding the Wire library to cover multiple ports, but the way it's written is not very multi-port friendly (it would take a complete rewrite).

The SPI library is the same, but we have the DSPI library that works with all SPI ports (DSPIx* defines).

For accessing other I2C ports you're going to have to do it manually with the registers I'm afraid.


samdesd

Fri, 02 May 2014 13:27:57 +0000

Thank you. In that case, uart is the only one having all ports config Arduino style? Sam


majenko

Fri, 02 May 2014 13:33:12 +0000

Uart is pretty much exactly Arduino. SPI can be made Arduino using the DSPI library:

#include <DSPI.h>

DSPI0 SPI;
DSPI1 SPI1;

void begin() {
    SPI.begin();
    SPI1.begin();
}
... etc ...

There are some differences with some of the functions, mainly because the PIC32's SPI works in a different way to the Arduino one - things like setting an absolute baud rate instead of a clock divider, etc.


samdesd

Fri, 02 May 2014 13:58:56 +0000

I will look into the mpide dspi sample. Thanks Sam