Pages: [1] 2   Go Down
Author Topic: SoftwareSerial problem , but only on 1284p  (Read 2262 times)
0 Members and 1 Guest are viewing this topic.
Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...

Code:
#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();
}
Logged

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :-(
Logged

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
#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:

Code:
#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))))
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
 
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep, its all about market share!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Miers 46500 France
Offline Offline
Sr. Member
****
Karma: 14
Posts: 322
EmbeddedAT .. From Concept to Prototype to Production
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :-(


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

Cheers Pete.
Logged

EmbeddedAT .. From Concept to Prototype to Production

Electronics and firmware design and project mentoring

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Skyjumper,
you mentioned....
Quote
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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 3
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :-(
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 - downloaded 22 times.)
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 - downloaded 32 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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



« Last Edit: December 23, 2013, 01:41:48 pm by retrolefty » Logged

Pages: [1] 2   Go Up
Jump to: