SoftwareSerial problem , but only on 1284p

Hi All...

I am playing with the Seed Studio Bluetooth shield, bought up the road at Radio Shack. I am testing it on two different boards, an Uno and my own 1284P board.

On the Uno, the code below works well, letting me exchange text with my Android phone.

On the 1284P board, I can send text to the phone, but data sent from the phone is not displayed on the terminal, leading me to believe that it is not actually being received.

I have checked the schematic and verified that the pins are correct. I even reversed which were the TX and RX pins, and of course rejumpered the shield, and the problem remained the same, indicating that there is not a hardware problem. I have also tried it with and without the internal pullup enabled.

Any ideas?

Thanks...

#include <SoftwareSerial.h>   //Software Serial Port

// Use these for 1284P board
#define RxD 14 
#define TxD 15 

// Use these for Uno 
//#define RxD 6
//#define TxD 7

#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup() 
{ 
  Serial.begin(9600);

  pinMode(RxD, INPUT);
  digitalWrite(RxD, HIGH); // enable pullup

  pinMode(TxD, OUTPUT);
  
  setupBlueToothConnection();
} 
 
void loop() 
{ 
  char recvChar;

  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
    }
    if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
      recvChar  = Serial.read();
      blueToothSerial.print(recvChar);
    }
  }
} 
 
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

I suspect this related to pin change interrupts. I now recall that I had to modify the original SoftwareSerial library to support the 1284P, so I'm now chasing this in the new library :frowning:

I made a lot of progress...

As I mentioned, I had modified the SoftwareSerial library under Arduino v0.22 to work with what at the time we called the Sanguino which was based on the 644P, and has the same pin out as the 1284P.

maniacBug had released his 1284P support, and I had asked him to do a version that matched the pin out nomenclature of the AVR Developers 1284P support, which he did. So i don;t know if the issue I had related to the Maniacbug 1284P or the AVR Dvelopers 1284P, but I'll get to the bottom of it.

In case anyone is interested, the changes I made are in pins_arduino.h. I have not checked yet to make sure i didn't break anything else. I suspect I probably did, but we'll see.

Here is the original:

#define digitalPinToPCICR(p)    (((p) >= 0 && (p) < NUM_DIGITAL_PINS) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 1 : (((p) <= 15) ? 3 : (((p) <= 23) ? 2 : 0)))
#define digitalPinToPCMSK(p)    (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
#define digitalPinToPCMSKbit(p) ((p) % 8)

Here are my changes:

#define digitalPinToPCICR(p)    (((p) >= 0 && (p) <= 31) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 1 : (((p) <= 15) ? 3 : (((p) <= 23) ? 2 : 0)))
#define digitalPinToPCMSK(p)    (((p) <= 7) ? (&PCMSK1) : (((p) <= 15) ? (&PCMSK3) : (((p) <= 23) ? (&PCMSK2) : (((p) <= 31) ? (&PCMSK0) : ((uint8_t *)0)))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 15) ? ((p) - 8) : (((p) <= 23) ? ((p) - 16) : ((p) - 24))))

That last part, I never understood what was going on there.

CrossRoads:
That last part, I never understood what was going on there.

I'll have som time this weekend to write a detailed explanation. I also need to compare these macros to ManiacBug's standard 1284P distribution and see if these are a bug or if there is something going on I am missing.

But on the plus side, the off the shelf Seeed Studios card works killer well on my board! I have to use SoftwareSerial but, the shield has a UART on it so I believe that I should not have a problem. The thing has been blasting data via bluetooth to my phone all night.

Of course, its BT 2.1, not BLE. Android needs BT 2.1 and Apple iOS needs BLE. What a pain!

Yep, its all about market share!

skyjumper:
I suspect this related to pin change interrupts. I now recall that I had to modify the original SoftwareSerial library to support the 1284P, so I'm now chasing this in the new library :frowning:

Is there any chance that you could send me the modified library you got working wit the 1284P please

Cheers Pete.

Hi Skyjumper,
you mentioned....

I'll have som time this weekend to write a detailed explanation. I also need to compare these macros to ManiacBug's standard 1284P distribution and see if these are a bug or if there is something going on I am missing.

Did you get any further with that? or the explanation?
I have been trying to figure out whats going on with the modification you suggested for the pin-change interrupts but cant figure it out.
I'm definitely a novice at this so any simplification you can pass along would be much appreciated.
Thanks...
Stewie

I am having a different issue. I am trying to use the softserial library with a 1284P using the mighty1284 core. The sketch I have works with the UNO but as soon as I try to compile it with the "Bobduino" I get the following:

C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:401: error: operands to ?: have different types 'int' and 'uint8_t*'
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:402: error: expected primary-expression before ']' token
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:402: error: operands to ?: have different types 'int' and 'uint8_t*'
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:417: error: expected primary-expression before ']' token
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:418: error: expected primary-expression before ']' token
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:418: error: operands to ?: have different types 'int' and 'uint8_t*'

Any ideas?

Thanks

Bruce

bvernham:
I am having a different issue. I am trying to use the softserial library with a 1284P using the mighty1284 core. The sketch I have works with the UNO but as soon as I try to compile it with the "Bobduino" I get the following:

C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:401: error: operands to ?: have different types 'int' and 'uint8_t*'

These errors are caused by a type mismatch. The type int is not the same as uint8_t*. int is, well, an int, while uint8_t* is a pointer to an 8 bit unsigned int (which really means something like unsigned char * - I would have to look in the header but I have to go out the door soon).

What is odd is that it works with the Uno.

I can attest that SoftwareSerial works with Mighty 1284P as well as Software Serial can work (which is to say, not very well). There is either an error in your version of SoftwareSerial or your Mighty1284 distro. In fact, are you using the very same code in the Uno and the Mighty1284P? If you have two different versions of Software Serial (one for Uno and one for Mighty 1284P) then the fact that you can build for Uno is irrelevant.

I see I made a promise a while ago I failed to keep. I still have the modified header files for SoftwareSerial on 1284P, and I can share. But I need to run now :frowning:

Yep, I know about the difference in the data types.

I could not find any references to "int" in soft serail.

serLCD library uses soft serial:

header snipet:

serLCD::serLCD(uint8_t pin) : SoftwareSerial(pin, pin)
{
pinMode(pin, OUTPUT);

CPP snipet:

class serLCD : public SoftwareSerial
{
public:
serLCD (uint8_t pin);

Originally pin was "int" but I change to uint8_t like softserial expects but still no luck compiling.

Uno and Goldilocs can compile with no issue even though the types were wrong in the original serLCD library.

Also I am the INPUT_PULLUP issue. I tried new updated files I was sent but that blow up my "fastpinMode" library I am using.

Other ideas would be helpful.

This issue has something to do with the pins_arduino.h file.

The attached file is for the Goldilock-20. If I substitute this into the bobuino variant folder then the sketch compiles with no problem.

Obviously this pins file can not be used for the Bobuino but it gives a good clue as far as what this issue is.

Any attention to this issue is appreciated.

pins_arduino.h (5.64 KB)

Okay, I've annotated the Goldilocks file with the differences from Bobuino file.
If we could get a real programmer to review the # define differences and if they should impact software serial, that would be great.
I personally would have just done a few lists with the pins, I find the C/C++ shorthand hard to follow.

pins_arduino_Goldilocks_vs_Bobuino.h (7.64 KB)

I'm hitting the same problem now. I am already using both hardware serial ports and need to use Software Serial and I have the same errors due to issues with the Bobuino pin map. If I try compiling with the AVR Developers pin map it works fine.

I found a reference to the Calunium board and a fix , but it doesn't cure my issue with Bobuino map.

I've tried comparing pin maps for different 1284 versions and against the standard Uno but it's out of my league to understand all the clever jiggery pokery.

It would be great if one of the more talented programmers could take a look and try and fix this to get Software Serial working on 644/1284.

I'm willing to donate a 644 if there is someone that needs the hardware to test on.

CrossRoads:
Okay, I've annotated the Goldilocks file with the differences from Bobuino file.
If we could get a real programmer to review the # define differences and if they should impact software serial, that would be great.
I personally would have just done a few lists with the pins, I find the C/C++ shorthand hard to follow.

These lines might be typos?

XTAL2 12| |29 - D29 PC7 (D23) TOSC2/PCINT23
XTAL1 13| |28 - D29 PC6 (D22) TOSC1/PCINT22

And as for the basic posted problem, might the root cause be in the software serial library code not accessing it's serial input and output pins per standard arduino methods?

Lefty

Yes, thanks, will update the pin assignment notes.
It's something in the #defines that is hosed I think.

It its the software serial library, I don't know how to chase that either.

Right, I'm feeling a bit chuffed at the moment as I've managed to get Software Serial working on my 1284P board with Bobuino pin mapping.

This is experimental as all I've done is hunt through lots of different examples for various 644/1284 pin maps and try and work out some logic.

I'd appreciate anyone else testing his, but please back up your original Bobuino pins_arduino.h files, or at least the bits you change.

Original lines

#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)

Replacement lines

#define digitalPinToPCICR(p)    ifpin(p,&PCICR,(uint8_t *)0)
#define digitalPinToPCICRbit(p) ifpin(p,digital_pin_to_pcint[p] >> 3, 0)
#define digitalPinToPCMSK(p)    (((p) <= 3) ? (&PCMSK3) : (((p) <= 7) ? (&PCMSK1) : (((p) <= 9) ? (&PCMSK3) : (((p) <= 13) ? (&PCMSK1) : (((p) <= 21) ? (&PCMSK0) : (((p) <= 29) ? (&PCMSK2) : (((p) <= 31) ? (&PCMSK3) : ((uint8_t *)0))))))))
#define digitalPinToPCMSKbit(p) ifpin(p,digital_pin_to_pcint[p] & 0x7, 0)

I'd also appreciate someone double checking my listing for the PCINT to Digital Pins below, as this is how I constructed the digitalPinToPCMSK(p) #define above. It is working for me with RX on 24 and TX on 21. Trying different combinations would be good to see if it works with other pins OK.

PCINT 7-0       PCMSK0       D14-D21
PCINT 15-8      PCMSK1       D4-D7, D10-D13
PCINT 23-16     PCMSK2       D29-D22
PCINT 31-24     PCMSK3       D0-D3, D8-D9, D30-D31

Software Serial is Pin Change Interrupt driven and uses direct port manipulation, but it looks like it gets the port/bit info from the pin mapping. I.e when you give it the pin numbers it has to convert to the relevant direct port/bits to control the correct hardware pins etc.

Well, the compiles with soft serial now.

Will work on it more later for the LCD dispaly.

Any idea about the INPUT_PULLUP issue (I know different problem) but it is a core issue.

Thanks

bvernham:
Well, the compiles with soft serial now.

Will work on it more later for the LCD dispaly.

Any idea about the INPUT_PULLUP issue (I know different problem) but it is a core issue.

Thanks

The two attached files should fix the INPUT_PULLUP issue for maniacbug core.

Back up your originals first as I make no warranties or guarantees on my code as I'm just an amateur. :wink:

wiring_digital.c (4.96 KB)

Arduino.h (5.56 KB)

Arduino.h:
int analogRead(uint8_t, uint16_t);

wiring_analog.C file:

int analogRead(uint8_t pin)

C:\Program Files (x86)\Arduino\hardware\maniacbug-mighty-1284p-68ed99c\cores\standard\wiring_analog.c:40: error: conflicting types for 'analogRead'
C:\Program Files (x86)\Arduino\hardware\maniacbug-mighty-1284p-68ed99c\cores\standard/Arduino.h:103: error: previous declaration of 'analogRead' was here

Had to modify the Arduino h and take out , uint16_t.

Will compile now but I have not tested the functionality.

I tested the new pins file and it seems to work as expected. I checked soft serial on all of the pins which I could. Didn't test D0 and D1 as this is the hard serial used for upload and download.

Thanks

Bruce