fredericplante/sanguino

Serial.read() does not work with Arduino-0018

Closed this issue · 11 comments

What steps will reproduce the problem?
1. Use the following code:

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    Serial.write(Serial.read());
  }
  delay(10);
}

2. load to sanguino using Arduino-0018 and latest sanguino-0018r1 code.
3. Note that typing into the terminal does not create a reply.

What is the expected output? What do you see instead?

It is expected that the serial port will echo any input. It doesn't, and
other tests show that this is because the Serial.read() isn't working.

What version of the product are you using? On what operating system?
Win32, Arduino0018, sanguino-0018r1, follwing instructions that came with
that package.

Please provide any additional information below.
The same code, compiled on Arduino0017 into a Sanguino using older Sanguino
files works properly. It also works properly under Arduino0018 on a
Atmega328, etc.

Original issue reported on code.google.com by ve9...@gmail.com on 5 Mar 2010 at 12:33

Can you let me know if when you send charactors to the board whether it ignores 
them
of it locks up the program

Original comment by teamcba@hotmail.com on 16 Mar 2010 at 11:52

Although the program above can not determine this, I'm certain from other 
contexts
that it is ignoring them.

Original comment by ve9...@gmail.com on 17 Mar 2010 at 12:28

I have uploaded a Hardware folder which is based on the 
sanguino-software-1.4-r1.zip
files, while this loses the 0018 commands it does fixes the Serial.read() while 
i
identify the problem 

Original comment by teamcba@hotmail.com on 18 Mar 2010 at 3:36

  • Changed title: Serial.read() does not work with Arduino-0018
  • Changed state: Accepted
Awesome! I will test this for you, hopefully by the weekend.

Original comment by ve9...@gmail.com on 18 Mar 2010 at 7:30

Original comment by teamcba@hotmail.com on 19 Mar 2010 at 7:28

  • Changed state: Started
Sanguino-0018r1_1_4.zip runs the test code above properly for me.

Original comment by ve9...@gmail.com on 20 Mar 2010 at 12:44

I've found the solution. For some reason the interrupts don't work correctly 
with SIGNAL. I replaced them with ISR and the newer _vect names and it's 
working for me.

Also changed some of the ifdef's to make it abit more compatible with the 
standard arduino distribution.

It seems that WInterrupts.c and wiring_private.h in the sanguino-0018r1 release 
aren't really adapted to the atmega644p but it seems to be working.

Original comment by unai...@gmail.com on 13 Jun 2010 at 3:26

Attachments:

When I re-installed sanguino-0018r1 and replaced the two files in comment #7, 
serial.read() worked for me. Thank you, unaimed.

Original comment by ve9...@gmail.com on 21 Jun 2010 at 12:35

Sanguino-0018r2_1_4.zip add to download page, includes unaimed's modified files 
from comment 7

Original comment by teamcba@hotmail.com on 23 Jun 2010 at 1:04

While the code changes by unaimed work for the 644P, I have found that it 
doesn't fix the issue with the non-P 644. The defines in HardwareSerial.cpp 
fall through if you have *644__ defined, and you get the SIGNAL versus the ISR 
routine defined. I have fixed this @my local copy and confirmed I can now 
serial.receive, whereas before, it would only transmit.

In "inline void store_char()" I have changed the defines to:

#if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || 
defined(__AVR_ATmega1280__)
ISR(USART0_RX_vect)
{
  unsigned char c = UDR0;
  store_char(c, &rx_buffer);
}
#endif

#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1280__)
ISR(USART1_RX_vect)
{
  unsigned char c = UDR1;
  store_char(c, &rx_buffer1);
}
#endif

#if defined(__AVR_ATmega1280__)
ISR(USART2_RX_vect)
{
  unsigned char c = UDR2;
  store_char(c, &rx_buffer2);
}

ISR(USART3_RX_vect)
{
  unsigned char c = UDR3;
  store_char(c, &rx_buffer3);
}
#endif

#if defined(__AVR_ATmega8__)
SIGNAL(SIG_UART_RECV)
unsigned char c = UDR;
store_char(c, &rx_buffer);
#endif

You will notice that I have unrolled the nested "if defined's". It doesn't 
increase code-size and it's easier to read the flow. I hate nested define 
statements where it's not absolutely necessary, but that's just me :)

Original comment by jan.ho...@gmail.com on 7 Sep 2011 at 6:47

Cleaning up old comments, excuse the noise.

Original comment by sutt...@gmail.com on 6 Sep 2012 at 12:19

  • Changed state: WontFix