stevemarple / Calunium

Arduino clone based on the ATmega644P/ATmega1284P
Other
34 stars 7 forks source link

SoftwareSerial does not compile with Calunium's pins_arduino.h #1

Open kfuglsang opened 12 years ago

kfuglsang commented 12 years ago

When including SoftwareSerial into the Arduino 1.0.1 IDE targeting Calunium 1284P the code wont compile due to compilation errors in SoftwareSerial.cpp.

arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)': arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:398: error: operands to ?: have different types 'int' and 'uint8t' arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:399: error: expected primary-expression before ']' token arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:399: error: operands to ?: have different types 'int' and 'uint8t' arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()': arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:414: error: expected primary-expression before ']' token arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:415: error: expected primary-expression before ']' token arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:415: error: operands to ?: have different types 'int' and 'uint8_t*'

I found that the problem occurs due to these lines in pins_arduino.h:

define digitalPinToPCICR(p) ifpin(p,&PCICR,(uint8_t *)0)

define digitalPinToPCICRbit(p) ifpin(p,digital_pin_to_pcint[p] >> 3,(uint8_t *)0)

define digitalPinToPCMSK(p) ifpin(p,__pcmsk[digital_pin_to_pcint[]],(uint8_t *)0)

define digitalPinToPCMSKbit(p) ifpin(p,digital_pin_to_pcint[p] & 0x7,(uint8_t *)0)

Changing them to this makes it compilable:

define digitalPinToPCICR(p) ifpin(p,&PCICR,(uint8_t *)0)

define digitalPinToPCICRbit(p) ifpin(p, digital_pin_to_pcint[p] >> 3, 0)

define digitalPinToPCMSK(p) ifpin(p,(uint16_t )__pcmsk[digital_pin_to_pcint[p]],(uint16_t )0)

define digitalPinToPCMSKbit(p) ifpin(p, digital_pin_to_pcint[p] & 0x7, 0)

kfuglsang commented 12 years ago

I'm starting to believe though, that the digitalPinToPCMSK(p) and in particular the __pcmsk array is incomplete. Any help on completing these would be appreciated.

stevemarple commented 12 years ago

I've not had chance to test this but the change to uint16_t* does look correct. Why do you believe __pcmsk is incomplete?

kfuglsang commented 12 years ago

I also added the index 'p' to the array lookup in digitalPinToPCMSK(p). To be honest, I don't quite recall why I had the belief that the __pcmsk array was incomplete. Most likely it was because I had a number of issues with my code on the Calunium-based board. I traced my problems back to a broken ethernet-library though.

stevemarple commented 11 years ago

I've applied the changes you suggested.

deladriere commented 9 years ago

Hi Steve I can compile but cannot use SoftwareSerial It works on Arduino Uno but the same code (SoftwareSerialExample) doesn't work on Calunium Did you succeed using it ? Thx

stevemarple commented 9 years ago

@deladriere With two hardware UARTs I've never had the need to use SoftwareSerial. What pins are you trying to use? If those pins are configured for other functionality that will prevent their use as normal I/O. Are you sure you have the correct hardware pins?

deladriere commented 9 years ago

I am trying this code TX pins are OK but no RX pins works (I've tried many pins)

/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
stevemarple commented 9 years ago

Digital pin 10 is the slave select (/SS) for the SPI port. It's normally recommended that it is kept as an output; you're not using SPI so I'm not sure if that still applies. Could you try another pin?

deladriere commented 8 years ago

Hi Steve just installed the lasted version and still cannot work with the SoftwareSerial SoftwareSerial mySerial(8, 15); // RX, TX If I use the Maniacbug board definition (from https://github.com/JChristensen/mighty-1284p) it works fine on the same hardware & pins (with the corrected pin number of course) Did you ever had success using SoftwareSerial?