Show Posts
Pages: [1] 2 3 ... 11
1  Development / Other Software Development / Re: SoftwareSerial - Bug on: July 09, 2014, 05:20:35 pm
I see this bug has not been fixed yet.  I"m still having the same problem myself.  The software serial takes 1.5s to time out from an imcomplete byte being transmitted.  I have statted a different thread on it becuase I didn't know this one was here.  Any resolve to this issue?

link to the thread as well as data I've accumulated to show this.  I thought it was an issue on the mac but it appears to be a bigger issue with software serial.

http://forum.arduino.cc/index.php?topic=253995.0

2  Using Arduino / Interfacing w/ Software on the Computer / Re: disable open BIT/BYTE canonical settings in TTY setup on: July 09, 2014, 04:22:23 pm
***UPDATE**** the problem does not exit when I build the code on my UBUNTU 14.04LTZ box using ECLIPSE IDE and a linux cross compiler.  The issue appears to be when I build the app on my MAC using XCODE.  When I open the port on my linux box there is no bit transmitted during the open tty call.  

Robin.. I appreaciate the help but without you even knowing what xcode is I don't think that you will be able to help me and I've found a linux fourm that better understands my problem so I'm talking with them about how to fix this problem.  Once I get it solved I'll post the fix.  If a mac device driver guy can chime in that might help me too.

I am not trying to do bi directional communication.  I think my code is well commented and documented and the problem is very duplicatable.  Thank you once again but this is all the input I can give to get help!
3  Using Arduino / Interfacing w/ Software on the Computer / Re: disable open BIT/BYTE canonical settings in TTY setup on: July 09, 2014, 01:50:09 pm
Below is the full Xcode program and a link to a screen shot from my logic analyzer.  My logic analyzer is attached to Pin 0 hardware RX and pin 3 Software Serial TX.  I shouldn't have to state the obvious but I will: the grounds are tied together.  As you can see in the captured waveform from the logic analyzer when I open the serial port i get a short 1 bit pulse and the software serial transmits that pulse for 1.5 seconds till it times out.  Then after my 2 second wait (hard coded into Xcode program I send my real data and the real data gets retransmitted to the software serial port.  if i send my serial data from Xcode during that long pulse being shown on the software serial port my data never gets transmitted out.  I'm using arduino 1.0.5 and Xcode 5.1.1  The Xcode program is just a console C program.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>

void init_port(int *fd, unsigned int baud) //configure serial port settings.
{
    struct termios options;
    tcgetattr(*fd,&options);
   
    switch(baud)
    {
        case 9600: cfsetispeed(&options,B9600);
            cfsetospeed(&options,B9600);
            break;
        case 19200: cfsetispeed(&options,B19200);
            cfsetospeed(&options,B19200);
            break;
        case 38400: cfsetispeed(&options,B38400);
            cfsetospeed(&options,B38400);
            break;
        case 115200: cfsetispeed(&options,B115200);
            cfsetospeed(&options,B115200);
            break;
        default:cfsetispeed(&options,B9600);
            cfsetospeed(&options,B9600);
            break;
    }
   
    options.c_cflag |= (CLOCAL | CREAD);    // Ignore modem controls
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;     // 8 bit chars
   
    options.c_cflag &= ~(PARENB | PARODD);  // shut off parody
    options.c_cflag &= ~CSTOPB; //no scts stop
    options.c_cflag &= ~CRTSCTS;    // no rts cts control
   
    options.c_iflag &= ~IGNBRK; //disable break processing
    options.c_iflag = 0;        // no echo
    options.c_iflag &= ~(IXON | IXOFF | IXANY); // no software flow control
   
    options.c_oflag = 0;        // no remapping
   
    options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG |IEXTEN);
   
    options.c_cc[VMIN] = 0;     // read doesn't block
    options.c_cc[VTIME] = 5;    // 0.5s read timeout
   
    tcsetattr(*fd,TCSANOW,&options);
}


int main(int argc, const char * argv[])
{
   
    const char serialport[] = "/dev/tty.usbmodemfa141"; // virtural TTY of Arduino
    int ttyport;        // serial port
   
    ttyport = open(serialport, O_RDWR | O_NOCTTY | O_NONBLOCK); //open the serial port
    if(ttyport == -1)   // if the serial port won't open let the user know
    {
        perror("Unable to open serial port\r\n");
        exit(EXIT_FAILURE);
    }
   
    printf("Opening Serial Port!\r\n");
    sleep(2);
   
    init_port(&ttyport,9600);         //set serial port to 9600,8,n,1
   
    write(ttyport, "TEST", 4);   // write the line to the serial port
    close(ttyport);     // close the serial port
   
    exit(EXIT_SUCCESS);
}

https://www.dropbox.com/s/colhp0us6a5wkrv/screenshot.png
4  Using Arduino / Interfacing w/ Software on the Computer / Re: disable open BIT/BYTE canonical settings in TTY setup on: July 09, 2014, 08:15:09 am
I am using an Uno R3 and I did use code blocks above with my xcode!  The code serial data is coming from the Mac.  Even if I send no raw data if I just do an open on the TTY I can see a one bit signal on pin 0 which causes a 1.5s signal on the software serial [tx] pin.  
ohh sorry you wanted the arduino code as well.  here it is:
Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

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

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
5  Using Arduino / Interfacing w/ Software on the Computer / Re: disable open BIT/BYTE canonical settings in TTY setup on: July 08, 2014, 09:07:18 pm
Robin,

Thanks for the reply.  Right now I have the circuit as a bare minimum.  Logic analyzer channel 1 attached to  pin 0 RX and logic anayzer channel 2 to software serial port.  I am using the software serial example code with the hello work serial prints removed.   No other hardware attached on other code on arduino.  When I open the tty on the mac I get a sudo start byte that goes low for 40us.  The tx line on the software serial then goes low for 1.5s and does not recover to send usable data.  The 10 bits per byte package on pin 0 looks great.  When I write to the serial port I get a start byte the 8 bytes and a stop byte.  If I do not wait for the tx line on the software serial to time out before I send real data the arduino software serial library garbled the data.  They are really 2 problems here.  One is I don't need an attention byte when opening the tty port.  That used to be common to wake up the modems back in the day.  Google searching this the raspberry pi used to do this as well but it was removed from the default operation of the tty port.  The other problem is the time out of the software serial on the arduino.  It does not time out from that  one bit until 1.5s pass.  The hardware serial port on the arduino has no problem ignoring this bit and processes the data properly.
6  Using Arduino / Interfacing w/ Software on the Computer / disable open BIT/BYTE canonical settings in TTY setup on: July 08, 2014, 01:12:59 pm
I'm using Xcode with an arduino and when I open a serial port I get a bit transmitted on the TX line to the Arduino RX pin.  This confuses software serial if I tunnel though the Arduino to the peripheral.   I can see it on a logic analyzer attached to the Arduino RX serial pin.    Right now I have a hack in place that after the port opens (delay 2 seconds in Xcode program) and let the software serial timeout before sending the real array of chars down the serial.  I've posted my x code ANSI C code below.


Code:
   ttyport = open(serialport, O_RDWR | O_NOCTTY | O_NONBLOCK); //open the serial port

How do I stop that one bit from being generated when i open the port?  I've included my TTY configure function below:
Code:
void init_port(int *fd, unsigned int baud)
{
    struct termios options;
    tcgetattr(*fd,&options);
    
    switch(baud)
    {
        case 9600: cfsetispeed(&options,B9600);
            cfsetospeed(&options,B9600);
            break;
        case 19200: cfsetispeed(&options,B19200);
            cfsetospeed(&options,B19200);
            break;
        case 38400: cfsetispeed(&options,B38400);
            cfsetospeed(&options,B38400);
            break;
        case 115200: cfsetispeed(&options,B115200);
            cfsetospeed(&options,B115200);
            break;
        default:cfsetispeed(&options,B9600);
            cfsetospeed(&options,B9600);
            break;
    }
    
    options.c_cflag |= (CLOCAL | CREAD);    // Ignore modem controls
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;     // 8 bit chars
    
    options.c_cflag &= ~(PARENB | PARODD);  // shut off parody
    options.c_cflag &= ~CSTOPB; //no scts stop
    options.c_cflag &= ~CRTSCTS;    // no rts cts control
    
    options.c_iflag &= ~IGNBRK; //disable break processing
    options.c_iflag = 0;        // no echo
    options.c_iflag &= ~(IXON | IXOFF | IXANY); // no software flow control

    options.c_oflag = 0;        // no remapping
    
    options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG |IEXTEN);
    
    options.c_cc[VMIN] = 0;     // read doesn't block
    options.c_cc[VTIME] = 5;    // 0.5s read timeout
    
    tcsetattr(*fd,TCSANOW,&options);
}
7  Using Arduino / Interfacing w/ Software on the Computer / Half Duplex RS485 linux Serial USB Programing in C on: June 18, 2014, 02:34:49 pm
I'm trying to setup half duplex communication in Ubuntu 14.04 in my program. I have my RS485 transceiver using the RTS line to toggle back and forth between transmit and receive. I'm using a speak when spoken to system and this program is the master. The problem is that the RTS isn't toggling back off when I'm done sending the package so I can receive the data. Basically I want it to turn the RTS high, send the data, turn the RTS low, then read the data. Any help would be great.  I"m using a USB to serial adapter with a Serial to RS485 transceiver for the master.  My TX from the master is great!  but the RTS isn't going low to switch the RS485 transceiver into receive mode.   The slaves all are Arduino's with RS485 transceivers attached.  I've been lookking at the signals with a scope and a logic analyzer and the RTS never goes low once the master send it's first packet.

Here is my linux Code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <sys/types.h>

#define BAUDRATE B38400
#define COMPORT "/dev/ttyUSB0"
#define _POSIX_SOURCE 1
#define FALSE 0
#define TRUE 1

#define STX_KEYPAD 0xE1
#define PAYLOAD_BUFF_SIZE 256

#define CRC_HI 0xD8
#define CRC_LOW 0xC3

volatile int STOP=FALSE;

int ser_port;
int bus_address = 1;
int message_length = 0;
struct termios oldtio,newtio;
unsigned char rxbuf[256];
unsigned char tx_flags = 0;

void openCommPort();
void sendSerial();
int setRTS(int level);

int main(void)
{
     printf("Starting...\r\n");
 openCommPort();
 setRTS(1);
 printf("Sending Serial Data\r\n");
 sendSerial();
 setRTS(0);
 //close(ser_port);
 printf("All Done\r\n");

     return EXIT_SUCCESS;
}

void openCommPort()
{
   ser_port = open(COMPORT, O_RDWR | O_NOCTTY | O_NONBLOCK);
   if (ser_port == -1)
    {
       perror(COMPORT);
       perror("Unable to open port");
       exit(-1);
    }

   if(tcgetattr(ser_port,&oldtio) <0)// save current port settings
    {
       perror(COMPORT);
       perror("Couldn't get old terminal attributes");
       exit (-1);
    }

    bzero(&newtio, sizeof(newtio));

    newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | CRTSCTS;     

     newtio.c_iflag = IGNPAR | ICANON;

    newtio.c_oflag = 0;

       // set input mode (non-C, no echo,...)
   newtio.c_lflag = 0;

   newtio.c_cc[VTIME]    = 0;   // inter-character timer unused
   newtio.c_cc[VMIN]     = 0;   // blocking read until 5 chars received

   tcflush(ser_port, TCIFLUSH);
   tcsetattr(ser_port,TCSANOW,&newtio);
 }

void sendSerial()
{
unsigned char tx_header[6];

tx_header[0] = STX_KEYPAD;
tx_header[1] = bus_address;
tx_header[2] = tx_flags;
tx_header[3] = message_length;
tx_header[4] = CRC_HI;
tx_header[5] = CRC_LOW;

if((write(ser_port, tx_header, 6)) != 6)
 {
     printf("Error sending data!  Not all bytes sent\r\n");
 }

}

int setRTS(int level)
{
int status;

 if (ioctl(ser_port, TIOCMGET, &status) == -1)
    {
        perror("getRTS(): TIOCMSET");
        return 0;
    }


if(level)
 {
     status |= TIOCM_RTS;
 }
 else
 {
    status &= ~TIOCM_RTS;
 }

if (ioctl(ser_port, TIOCMSET, &status) == -1)
{
    perror("setRTS(): TIOCMSET");
    return 0;
}

return 1;
}
8  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 04:07:38 pm
For anyone interested I found the answer I was looking for.  When writing the variable locally to a function the variable is written to the stack and is overrunning part of the stack.  When I declare the variable globally it is written to a different part of the stack and happens to be over written a different area of memory that is not pertained to my program. 
9  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 03:05:00 pm
I just tried it on a different machine and it failed both times too.  so here is where it gets really confusing.  Running ubuntu 12.04 64-bit and Arduino 1.0 it works when i declare it globally and not locally.  

When i run it on Arduino 1.0.5 on widows7 pro 64it blows up and i get 10 both ways.  So either it's my machine doing something differntly or something different in the linux compiler then the windows.

I want to see it fail no matter where the declaration of the variable is for the record.
10  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 03:00:52 pm
My apologies.  I was fixing my reply in 8 as you typed your reply I saw the error there and wanted to correct it.

the http://arduino.cc/en/Reference/int does state 16bit for anything but the due and 32 bit for the due.  I am used to working in the 32 bit world and I do understand that was a mess up on my part to use a 32 bit int for a 16 bit int container.  Still curious as why it doesn't blow up completely with a global variable like it does for a local.
11  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 02:56:51 pm
You are correct i'm only basic this on 16bit unsigned ints of 65535.  I know it blows up on anything larger.  I understand that I should be using an unsigned long to convert FF FF FF FF to 4294967295.  I do know that parts of the code have holes in them  but for unsigned ints of 65535 that code works for a global unsigned int but not a local unsigned it.  My point is it shouldn't work either way!
12  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 02:49:45 pm
I think were getting off topic here though.  Why does it work when the unsigned int is declared globally and not locally?  Are global variables different size then locally?
13  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 02:44:52 pm
actually the board i"m running it on is not terrible important.  I'm running it on an arduino Uno though.  IT does work properly when I run the last code I posted no matter where I place the variable though.
14  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 02:38:23 pm
Can no one explain why this is working as a global not a local variable though?  I understand the syntax error but that isn't my question. 


I know this is proper syntax and it works like a charm but I found out the issue in question purely by accident and that is more what my question is based on.  Why does it work with a global and not with a local variable.  That is really the only question.  According to C structure this way is the proper way to do what I'm trying to do for an 8bit system and it works like a charm no matter where the variable TcpMessageLengthCheck() is declared.

Code:
int ParseMessage()
{

  unsigned int TcpMesageLengthCheck = ((int)wirelessMessage[1] << 24) | ((int)wirelessMessage[2] << 16) | ((int)wirelessMessage[3] << 8) | ((int)wirelessMessage[4]);
  unsigned int messageNumber = wirelessMessage[5];
 
  Serial.print("Message Length Counter: ");
  Serial.println(messageLengthCounter);
  Serial.print("TCP Message Length Check: ");
  Serial.println(TcpMesageLengthCheck);
     
  if(wirelessMessage[0] == 'D')
  {
    if(TcpMesageLengthCheck == messageLengthCounter)
    {
     
      Serial.print("Message Number: ");
      Serial.println(messageNumber);
      Serial.println(" ");
      Serial.println(" ");
    }
    else
    {
      Serial.println("Incomplete message receiced");
      Serial.println(" ");
      Serial.println(" ");
    }
  }
  else
  {
    Serial.println("NOT THE RIGHT MESSAGE TYPE");   
  }
  return TcpMesageLengthCheck;
}
15  Using Arduino / Programming Questions / Re: unsigned int issue on: May 20, 2014, 02:15:25 pm
Paul even with an int Cast it doesn't work. when I declare the variable locally but it does when I declare it globally.  I think it's a bug in the compiler to be honest.

Code:
unsigned int TcpMesageLengthCheck = ((int)wirelessMessage[4]) + ((int)wirelessMessage[3] >> 8) + ((int)wirelessMessage[2] >> 16) + ((int)wirelessMessage[1] >> 24);
Pages: [1] 2 3 ... 11