Mega/Uno incompatible sketch.

Hi i have a sketch working on a arduino Mega, it uses a rewritten hardwareserial library.
Now i want to upload it on my UNO, and yes i have rewritten the code because only one serial is available on the UNO. So i'm reading Serial data and sending it to softwareserial which i sniff with a USB/TTl adapter and Putty.

I think there are some alternations made in the hardwareserial that are not compatible with my UNO, i think it has to anything with different kinds of (registers/UCSR0A/UDR0 stuff)
Is there someone who knows how this works and who can check the alternated hardwareserial library for me.

I realy like to get it working on my UNO instead of Mega

EMSbusReceiveExample1.ino (21.8 KB)

NefitSerial.cpp (8.17 KB)

NefitSerial.h (3.22 KB)

Datasheet!

Mark

yes thanks but i tried a lot of different options, but can't find the correct one.
Any hints?

holmes4:
Datasheet!

Mark

can you please give me a hint, i'm bussy for three days for getting it to work.
I like the UNO to get some RX data from a EMS bus, the UNO has to decode it and send it through softserial to serail adapter so i can see the data.
Is it possible at the same time, or can't i use the 1 and only hardwareserial for this purpose???

Maybe something wrong with addressing or registers or baudrate????

Why an UNO? Why can't you keep using the solution that already works?

If you need something smaller than a Mega, consider the Micro. It has hardware serial independent of the USB serial, so you can decode serial data and send it to the PC without any messing around with other hardware or softwareserial. If you need true serial-to-serial, then a Teensy is even smaller and has good hardware serial for 3 ports, plus USB serial too.

The Mega has 3 hardware serial ports. No need to user software serial.

ieee488:
The Mega has 3 hardware serial ports. No need to user software serial.

Does it not actually have 4 hardware serial ports ?

In what way have you changed the Serial code, and in what way does it not work?
I'm pretty sure that the ATmega2560 and ATmega328 UARTs are essentially identical...

"xxSerialxx.begin(9700);" - really? 9700?

UKHeliBob:
Does it not actually have 4 hardware serial ports ?

I mis-remembered. That should be 3 hardware ports in addition to the one that comes Uno.

yes i have rewritten the code because only one serial is available on the UNO. So i'm reading Serial data and sending it to softwareserial

If I try to compile your code, I get that nefitSerial1 is undefined. I don't SEE anything in there that make nefitSerial1 be a SoftwareSerial port if the hardware doesn't exist; is this supposed to be the changed code, or the original Mega code?

the example i posted was intended for the Mega,that's the one that works.

  • Rewrite and use softwareserial on Mega works also.

  • If i rewrite it to XXXSerial and use softserial it doesn't work on the UNO. The data won't be decoded and registers stay empty.

Why did you change the hardware serial library ?

The hardwareserial is changed to detect the end/stop/break of the message , a 11bit Null.
And for the record I found the parts/sketches on the Internet and was planning of using it only for decoding the bus message. The rest I edit to fit my needs. Only the part thats edited in the hardwareserial I can't seem to understand fully understand.

And I was using a uno cause I have another uno with wifi from arduino.org so I want to use that one to upload my data to my domoticz server. So I'm looking for an arduino with multiple UARTS and wifi.

It might help if you post the code that isn't working...

This ombouwsoftserial.ino is the one using softwareserial and is not working.
I mad an other one using Ciao.write for wifi output and is also not working (ombouwuno9600.ino)

ombouwuno9600.ino (17.9 KB)

ombouwsoftserial.ino (19.4 KB)

  1. Does your version of hardware serial work on the Uno ON ITS OWN without software serial? Answer yes or no

  2. Did you find your new hardware serial (the one you say works on the mega) on the internet Answer yes or no

  3. Did you change any of the code in the version of hardware serial that works on the mega Again yes or no

Mark

  1. it does work but not the decoding part
  2. yes

holmes4:

  1. Does your version of hardware serial work on the Uno ON ITS OWN without software serial? Answer yes or no

  2. Did you find your new hardware serial (the one you say works on the mega) on the internet Answer yes or no

  3. Did you change any of the code in the version of hardware serial that works on the mega Again yes or no

Mark

  1. No it doesn't decode the data
  2. Yes
  3. didn't change the new hardwareserial

i think this is the part where it goes wrong:

inline void store_char(unsigned char c, bool fe, NefitSerial *s)
{
int i = (unsigned int)(s->_rx_buffer_head + 1) % SERIAL_BUFFER_SIZE;

// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != s->_rx_buffer_tail) {
s->_rx_buffer[s->_rx_buffer_head] = c;
s->_error_flag[s->_rx_buffer_head] = fe;
s->_rx_buffer_head = i;
}
}

No that code is hardware independent.

  1. What 3 pins are you using for software serial?

  2. What 3 pins are you using for this other device?

The hardware serial you found on the net was NOT written to run on an Arduino. Look at the comments at the start of the cpp (modification history).

/*
  NefitSerial.cpp - Hardware serial library for Wiring
  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  
  Modified 23 November 2006 by David A. Mellis
  Modified 28 September 2010 by Mark Sproul
  Modified 14 August 2012 by Alarus
*/

First version 06 ! Any one know when the first Ardunio was?

I assume that both hardware serials stem from the one provided by ATMEL

Then look at the way the #ifdef's are done. For example

/*
 * on ATmega8, the uart and its bits are not numbered, so there is no "TXC0"
 * definition.
 */
#if !defined(TXC0)
#if defined(TXC)
#define TXC0 TXC
#elif defined(TXC1)
// Some devices have uart1 but no uart0
#define TXC0 TXC1
#else
#error TXC0 not definable in NefitSerial.h
#e

I'd say the code was written for the ATmega8 and then modified to let it work with the Arduino mega.

I suspect that all the hardware dependent bits of the code are being lost in the c pre-processor. Which is why it compiles.

Which brings us back to - datasheets! Do you have the one for this thingy you are trying to talk to?

Find it and then look at the list of options provided by the Arduino H/W serial Look at the begin method.

But first which pins are you using.

Mark