Created Sun, 15 Jan 2012 20:06:33 +0000 by yoshco
Sun, 15 Jan 2012 20:06:33 +0000
i would like to use WIRE to comm between an UNO and a chipkit MAX32
I2C: Synchronous serial interface. Pin 21 should be connected to (SCL), Pin 20 (SDA). This uses I2C1 (SDA1, SCL1) in the PIC32 microcontroller.
thanks for comments
Sun, 15 Jan 2012 20:53:39 +0000
A guy wired them to make a pinball machine in "What are you developing" forum. He used SPI and a 3.3-5V logic level converter.
Sun, 15 Jan 2012 21:37:59 +0000
thanks, i dont have a logic converter at hand, is there an alternative?
Sun, 15 Jan 2012 22:02:22 +0000
Well.. Arduino might recognise 3.3 logic. So one wire can connect with nothing more. You could add a resistor to arduino out chipkit in to take the 5 v down to 3.3 V. It might work but it's a little risky.
Sun, 15 Jan 2012 22:06:22 +0000
risky is my middle name :) thnx
Sun, 15 Jan 2012 22:36:15 +0000
im sorry im not entrily clear on this.
On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS).
SPI docs you mention only one wire, which ones should i discard? the arduino should be the master?
Sun, 15 Jan 2012 23:22:05 +0000
So.. Chipkit slave, Arduino master would be like this:
This should lower the voltages into the chipkit. Make sure you set the jumpers right. Otherwise, fried chipkit again.
Sun, 15 Jan 2012 23:38:11 +0000
ok...
i think i'll wait for the logic converter :?
when it arrives, should i put it on the MOSI<>MOSI line ?
Mon, 16 Jan 2012 00:01:38 +0000
put it on all 4 or at least on mosi and miso
Mon, 16 Jan 2012 00:13:39 +0000
ok, i'll try to find a local alternative to these
Mon, 16 Jan 2012 01:06:42 +0000
Or you could use those converters with the UART rx and tx, only 2 wires, and simpler asynchronous data transfer. I don't know how to wire those though.
Tue, 17 Jan 2012 13:16:17 +0000
Hi there,
I'm the guy with the pinball machine. :) Actually, I only use SPI to communicate with my display and SD card reader from Chipkit. The communication between Arduino and Chipkit is hardware serial. Very simple and very reliable. I only wired transmit to receive and vice versa, Serial3.begin(xxx) on both cards and went about my business as usual.
Basically, the Max32 is reading SD data and handling lights and display, while reading new commands from the Arduino. The Mega2560 (Arduino) is acting as a input and game logic master and sends "playAnimation" serial commands etc to Max32.
Tue, 17 Jan 2012 17:48:30 +0000
Do you use some kind of a trigger before data transmission? Or you can just serial.print on one and serial.read on the other such that the printer waits for the reader to confirm receiving the transmission?
Wed, 18 Jan 2012 15:18:43 +0000
Exactly.
I'm using a short blocking loop, the receiving end must transmit a "OK" upon receiving all data so that the sending unit knows that the receiver got the transmission. If there's no "OK" after a short interval (100ms) a resend is made and the waiting continues. After 3 failed attempts the data is lost and the program continues execution.
The waiting compensates for any misalignments between the two units since no data will be resent until we know that the other end has had a chance to fetch it. The Serial interfaces are also async and buffered so no data should (in theory) ever be lost. I also send the number of bytes I'm sending so that the other ends knows how much data it should expect. Care should be taken to not fill the Serialbuffers thou, so we don't lose data.
This is ok for my system since all credits, game mode, switch statuses etc are resent every frame anyway, so in case of failure it should mean a delay in animation playback etc at most.
I've also hooked up the reset switch of the slave unit (Chipkit) to Arduino just in case, so that I may reset that unit in case it should hang or fails to receive data for X number of loops. I'm currently sending at 256 000 bps between the two so there's little or "no" delay in communication and it has yet to fail me.
The only thing I had to do just to make sure it won't fail is to ensure that the starting order is always the same - I.e the slave must be entirely booted before the master starts sending commands. So I do a reset of the slave first, and delay the rest of the Arduino boot for a number of seconds until the Chipkit is booted. The chipkit in turn after it has booted waits for the first commands from the Arduino before it starts to loop.
This way I get a good sync between the two boards and I know that they're both ready to send and receive data etc.
Wed, 29 Jan 2014 17:14:09 +0000
This is a fantastic write up. Thank you. I'm going to be using something very similar.
Wed, 01 Jul 2015 01:46:23 +0000
Hi there, I'm the guy with the pinball machine. :) Actually, I only use SPI to communicate with my display and SD card reader from Chipkit. The communication between Arduino and Chipkit is hardware serial. Very simple and very reliable. I only wired transmit to receive and vice versa, Serial3.begin(xxx) on both cards and went about my business as usual. Basically, the Max32 is reading SD data and handling lights and display, while reading new commands from the Arduino. The Mega2560 (Arduino) is acting as a input and game logic master and sends "playAnimation" serial commands etc to Max32.
I'm trying roughly the same thing, kinda. I have a Max32 and two Arduino Uno's that I'm trying to link using serial, specifically Serial2 to one Uno, and Serial3 to the other. The idea is that the Max32 is the main controller that fires commands to each Uno (one has an LCD, the other has an MP3 shield), but for the life of me I can't get it to work. With the serial disconnected from the Max32, I can operate the Uno's commands using the console on my PC, but I'm getting no love from the Max32. Are you sure you didn't do anything special to get the Max32 to play with the Arduino?
At first I thought it was the difference in logic levels, but you're using a Mega 2560 which is also 5v. So I'm baffled.
Wed, 01 Jul 2015 11:10:50 +0000
What baud rate are you trying to communicate at? The Arduino is unable to communicate reliably at higher baud rates due to the clock being unable to accurately divide down to the right kind of values, but the chipKIT boards, because of the higher speed master clock, can do it more accurately. As a result the Arduino sometimes can't communicate through serial with the chipKIT boards. Try running at a lower baud rate (9600).
Fri, 04 Sep 2015 09:09:27 +0000
What baud rate are you trying to communicate at? The Arduino is unable to communicate reliably at higher baud rates due to the clock being unable to accurately divide down to the right kind of values, but the chipKIT boards, because of the higher speed master clock, can do it more accurately. As a result the Arduino sometimes can't communicate through serial with the chipKIT boards. Try running at a lower baud rate (9600).
Majenko, I respect your work and contributions to the community... but are you sure about this? :) I've driven communication, one-sided thou, at much higher speeds than 9600 baud. Can't vouch for it's stability however as I'm usually only doing it for 15-20 min in a row...
Fri, 04 Sep 2015 09:52:11 +0000
I have had first hand experience of not being able to communicate between an Uno and an Uno32 at baud rates over 115200 baud. Some rates are better than others, but there is some lack of tolerance between the boards at higher speeds.
Here is a little table I built to show the error rates between the two chip's baud rate generators and real baud rates. This assumes a 1:1 system clock to peripheral bus clock on the PIC32, which you get by default with the current downloadable bootloader, but some seem to have an 8:1 ratio which makes the PIC32 errors much worse.
[attachment=0]brgerror.png[/attachment]
As you can see at 115200 baud the PIC32 is pretty close to the right speed. The Arduino, though, is 2.12% out. While that may be fine for short bursts of data (a handful of bytes) for more sustained transfers it could cause too much drift to be sustainable. Even at 57600 baud there's a bit too much of a difference for my liking.
At higher multiples of the same base baud (230400, 460800, etc) the Arduino's drift becomes just too great for reliable communication. Above 115200 baud the Arduino is only really capable of "round number" baud rates - 250000, 500000, 1000000 and 2000000. Those are all easily achievable from a "round number" system clock of 16MHz or 80MHz, so both chips run with a perfect 0% error. It's impossible for the Arduino to even come close to 1152000 baud though, instead generating 2MBaud at over 73% error - a far cry from the PIC32's 2.12% error at 1176470.59 baud.
So if you want communication between a chipKIT and an Arduino above 115200 baud very careful selection of the baud rate is required. Stick round numbers like 125000, 250000, 500000, 1000000 or 2000000 baud and you'll be OK. Anything else is asking for trouble.
Fri, 04 Sep 2015 09:53:17 +0000
Here you may see the baudrates for arduino stuff - for both 8MHz and 16MHz the higher baudrates ie 115k2 are off by few percent. That may cause issues, or may not :) http://wormfood.net/avrbaudcalc.php
Fri, 04 Sep 2015 12:46:59 +0000
I have had first hand experience of not being able to communicate between an Uno and an Uno32 at baud rates over 115200 baud. Some rates are better than others, but there is some lack of tolerance between the boards at higher speeds. [...] So if you want communication between a chipKIT and an Arduino above 115200 baud very careful selection of the baud rate is required. Stick round numbers like 125000, 250000, 500000, 1000000 or 2000000 baud and you'll be OK. Anything else is asking for trouble.
Ah, I knew I should have known better. :D I've only ever used short bursts of data, and currently at 115200 and have yet to experience issues (or have I ... in regards to my other post). I'll update the code to use even numbers instead, 0% difference seems a lot better to me!
Thanks! :)