dcs-bios-arduino-library
dcs-bios-arduino-library copied to clipboard
ATmega32U4 supported as a RS485 Master/Slave
Is it possible to get the ATmega32U4 supported as a RS485 Master/Slave? working on a project we we're using the Sparkfun Pro Micro with HID but would the rest of our pit we'd like to also use it as RS485 Master/Slave.
It looks like the issue is with the UART
added my log file to show the errors
My Sample test code
#include <Arduino.h>
/*
The following #define tells DCS-BIOS that this is a RS-485 slave device.
It also sets the address of this slave device. The slave address should be
between 1 and 126 and must be unique among all devices on the same bus.
*/
#define DCSBIOS_DEFAULT_SERIAL
#define DCSBIOS_RS485_SLAVE 1
/*
The Arduino pin that is connected to the
/RE and DE pins on the RS-485 transceiver.
*/
#define TXENABLE_PIN 2
#include "DcsBios.h"
/* paste code snippets from the reference documentation here */
void setup() {
DcsBios::setup();
}
void loop() {
DcsBios::loop();
}
Note that I have tried this with VSCode+PlatformIO and Arduino 1.8.6 both give same errors
If you're comfortable with it, please try giving the "32U4_Support" branch of my fork a try. If that works I will submit the pull request for this repo. You will also need to add a #define UART1_SELECT to your script and remove the #define DCS_BIOS_DEFAULT_SERIAL when you are using RS485. I don't have the hardware to test this out on a live RS485 network, but it does appear to compile correctly now.
For reference: the root of this issue appears to be that the 32U4 indexes its UART port off of 1 instead of zero. UART0 does not exist, UART1 does. I don't have a deep enough understanding of the RS485 code to comment on any further effects that this might have outside of RS485, but my current implementation essentially just tells BIOS to pretend that it is an ATmega2560 instead of a 32U4 for the purposes of communication. @talbotmcinnis may have a clearer knowledge of what that portion of the code is actually doing.
Happy to try. It did compile the slave code see attcahed for one message in it
C:\Users\smgvb\Documents\Arduino\libraries\dcs-bios-arduino-library-32U4_Support\src/internal/DcsBiosNgRS485Slave.cpp.inc: In member function 'void DcsBios::RS485Slave::rxISR()':
C:\Users\smgvb\Documents\Arduino\libraries\dcs-bios-arduino-library-32U4_Support\src/internal/DcsBiosNgRS485Slave.cpp.inc:79:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
state = RX_WAIT_ADDRESS;
~~~~~~^~~~~~~~~~~~~~~~~
C:\Users\smgvb\Documents\Arduino\libraries\dcs-bios-arduino-library-32U4_Support\src/internal/DcsBiosNgRS485Slave.cpp.inc:83:4: note: here
case RX_WAIT_ADDRESS:
^~~~
It does not compile the RS485 Master code though for me (not sure if you address master or not) here's the log from that compile.
I really appreciate your help on this
I looked at the code around that point and it seems to be expected to fall thru, refering to this
C:\Users\smgvb\Documents\Arduino\libraries\dcs-bios-arduino-library-32U4_Support\src/internal/DcsBiosNgRS485Slave.cpp.inc:79:12: warning: this statement may fall through [-Wimplicit-fallthrough=]
state = RX_WAIT_ADDRESS;
Correct, that fall through is intentional. That particular message is only a warning, so it shouldn't be an issue, but I've corrected it now. As for the master version: I'll look into it. Theoretically, it should be possible, but I'm learning this codebase on the fly.
Been awhile on this issue so checking in to see if there's been any progress on this?
Kind of gave up on this ask, I've gotten it compiling now on the Pro-Micro in both Master/Slave modes, really does come down to the 32U4 has no UART0 that's reserved for the CDC USB port, so UART1 is the first UART available. my current code is still untested and have to check the UART BAUD settings. I'll eventually do a PR once fully tested for it to incorporate if desired.
oh and also believe I got IRQ working, also to be tested
@kbastronomics Did you ever get this working?
I made the mistake of buying ATMEGA32U4 Pro Micro's instead of Nano's, and rather than let them go to waste I'm hoping you've solved this issue.
Partially, Slave seems to be working. master is a little more work.