Jump to content
al1fch

Serial1 or SofwareSerial ?

Recommended Posts

Hi

I want to drive serial things (WiFi RN-171, BlueTooth module...) and keep serial through USB for Stellaris<-> PC connection.

Is there yet a way to use Hardware Serial1 or SoftwareSerial with current Energia for Stellaris ?

Share this post


Link to post
Share on other sites

Hi Rei Vilo

Needing Rx(1) and Tx(1) (PB_0 and PB_1) I have tried "Serial1.begin(9600)" just as I do with Arduino Mega and Arduino Leonardo for alternate Uarts.

Error message is :  error: 'Serial1' was not declared in this scope

-Is there any thing else to do with Energia for extra Uarts ?

-Does current Energia supports Stellaris's  multiple Uarts ?

Share this post


Link to post
Share on other sites

Use `selectModule()` as described in https://github.com/energia/Energia/blob/master/hardware/lm4f/cores/lm4f/HardwareSerial.cpp#L228

 

HardwareSerial mySerial; 
void setup() { 
  mySerial.selectModule(3); 
  mySerial.begin(9690); 
  ... 
}

The same logic applies for I2C and SPI.

 

As an alternative, declare the variable as described in https://github.com/energia/Energia/blob/master/hardware/lm4f/cores/lm4f/HardwareSerial.cpp#L130

 

 

HardwareSerial Serial2(2);

Share this post


Link to post
Share on other sites

Hello

 

the methodology described here does not really work.

Indeed, the creation of different UARTS works correctly but the resultant binary  gives no output signals on the UARTS that have been created.

If we reduce the program to a single uart, it does not work either unless you removed the call  .selectModule (0-6).

 

see example:

HardwareSerial serial1;
HardwareSerial serial2;
 
 
void setup() {
 
  serial1.selectModule(0);
  serial1.begin(9600);
  serial2.selectModule(1);
  serial2.begin(9600);
 } 
 
void loop() {
 
serial1.write("Hello");
serial2.write("Hello");
}
 

 

No compiation errors but binary execution on stellaris give no output signal on TX 0 or 1.
I monitor the signal with an logic analyser on all TX pins .
if serial1.selectModule(0) and serial2.selectModule(1) are removed the UART 0 is ok 
 
Any ideas
JC Ragris
 

Share this post


Link to post
Share on other sites

Does anybody has a working example for uart1 ? Sounds stupid, but i tried this - no success.

 

 

 

#include "Energia.h"

void setup() {

Serial1.begin(9600);

}

void loop() {
  Serial1.println("abcdefghijklmnopq");
  delay(1000);
}
 

 

 

I connected J1-3 and J1-4 to buspirate to check for uart output - shows nothing.

 

regards

Mike
 

Edited by bluehash
Please use code tags next time. Welcome to Stellarisiti!

Share this post


Link to post
Share on other sites

I also found Serial1 on PC_5 & PC_6. The oft referred (and beautiful) Pin diagram:  https://github.com/energia/Energia/wiki/Hardware shows RX(1) & TX(1) on both PC_5,PC_6 and on PB_0,PB_1 (pins 3,4).  The Launchpad User Manual also shows U1 on pins 3 & 4. 

I haven't been able to get any data out on these pins and I don't see any reference in HardwareSerial.cpp; is it possible to get Serial on PB_0,PB_1?

Share this post


Link to post
Share on other sites

....

is it possible to get Serial on PB_0,PB_1?

 

of course :)

This will be needed in the future for WizFi Boosterpack library (maybe this weekend...) :)

 

diff for latest GitHub HardwareSerial.cpp:

95c95
<     {GPIO_PA0_U0RX, GPIO_PA1_U0TX}, {GPIO_PC4_U1RX, GPIO_PC5_U1TX},
---
>     {GPIO_PA0_U0RX, GPIO_PA1_U0TX}, {GPIO_PB0_U1RX, GPIO_PB1_U1TX},
103c103
<     GPIO_PORTA_BASE, GPIO_PORTC_BASE, GPIO_PORTD_BASE, GPIO_PORTC_BASE,
---
>     GPIO_PORTA_BASE, GPIO_PORTB_BASE, GPIO_PORTD_BASE, GPIO_PORTC_BASE,
109c109
< // The list of i2c gpio configurations.
---
> // The list of UART gpio configurations.
114c114
<     GPIO_PIN_0 | GPIO_PIN_1, GPIO_PIN_4 | GPIO_PIN_5,
---
>     GPIO_PIN_0 | GPIO_PIN_1, GPIO_PIN_0 | GPIO_PIN_1,

HardwareSerial.cpp.diff.7z

Share this post


Link to post
Share on other sites

It's me again - still have problems withe uarts.

TX/RX from Stellarpad are connected to TX/RX from FTDI USB-Serial Device.

I can only receive chars from Stellar but when i try to send some back, nothing is received.

To make it clear UART-TX from Stellar works fine but no UART-RX.

Tested with following code:


HardwareSerial mySerial(3); 

void setup() { 
  unsigned char c = 0;
  //mySerial.selectModule(3);
  
  mySerial.begin(9600); 

  mySerial.println("Test starts ... ");
  while( c != 'U')
  {
    c = mySerial.read();
    delay(200);
    mySerial.print(c);
  }
}

void loop()
{
  
}

I checked it with Serial 1 on PC_4 and PC_5 and with Serial 3 on PC_6 and PC_7.

Oh and i updated the lm4 part of the lib 2 weeks ago and my HardWareSerail.cpp looks like the one on github.

 

Any hints ?

Share this post


Link to post
Share on other sites

@pici

 

check this one (without HardwareSerial mySerial(3);  ):

void setup() {
 unsigned char c = 0;

 Serial3.begin(9600);
 
 Serial3.println("Test starts ... ");
 while( c != 'U')
 {
  if (Serial3.available())
  {
   c = Serial3.read();
   delay(200);
   Serial3.print(c);
  }
 }
}
 
void loop()
{
}

Share this post


Link to post
Share on other sites

@reaper7

 

Yeap !

Works fine now. The available() call is also very helpfull - don't know how i could oversee this :wacko: .

 

Anyway thanks for your help !!! :D

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...