Serial port set the MSB to 1 always... any clues?



Hi all,
I have spent some time on writing a simple code that works with the
serial port on my embedded system (Mica2 from crossbow) that has an
Atmel 128L. After debugging the code upmteeth time and with help from
http://www.easysw.com/~mike/serial/serial.html, i seem to have it
working with the correct baud rate being set.
However, each byte that I receive in my embedded processor seems to
have its MSB set: e.g. if I send 4 as the first byte, the received
byte is 128+4=132, if I send 9 it is 128+9=137. Is there anything I am
missing here? I get no write errors on my PC side, and I have tried it
on different computers, nothing seems to work. Has any body had this
issue before? Thank you.

Here is the code that I use to set it to 8N1 (I dont want to use any
parity).

int setSerial( char *p_szPlatform,
struct termios *p_pNewtio )
{
if (tcgetattr(input_stream, p_pNewtio) == -1)
{

printf("Error getting tty attributes %s(%d).\n",
strerror(errno), errno);
return -1;
}
//to setup 8N1
p_pNewtio->c_cflag &= ~PARENB;//make sure parity bit is not set
p_pNewtio->c_cflag &= ~CSTOPB;
p_pNewtio->c_cflag &= ~CSIZE;//mask character size bits
p_pNewtio->c_cflag |= CS8 | CLOCAL | CREAD;

cfsetispeed(p_pNewtio, BAUDRATE_MICA2);
cfsetospeed(p_pNewtio, BAUDRATE_MICA2);

p_pNewtio->c_iflag |= IGNPAR;
//chooising raw input
p_pNewtio->c_iflag &=~(ICANON|ECHO|ECHOE|ISIG);

/* Raw output_file */
p_pNewtio->c_oflag &=~OPOST;

return iRet;
}

///The code where I write to the serial port is as follows
tcflush(input_stream, TCIFLUSH);

if (tcsetattr(input_stream, TCSANOW, &newtio) == -1)
{
printf("Error setting tty attributes %s(%d).
\n",strerror(errno), errno);
}
printf("Input baud rate changed to %d\n", (int)
cfgetispeed(&newtio));
printf("Output baud rate changed to %d\n", (int)
cfgetospeed(&newtio));
//send a packet via the serial port to the mote to test if the serial
is correctly set or not
typedef struct _app_header
{
uint8_t len; //the phyHeader

uint8_t type;//just for test purposes
int16_t crc; //the crc reqd by the physical layer
} __attribute__ ((packed)) AppHeader;

AppHeader pkt;
uint8_t* buf= (uint8_t*)&pkt;

pkt.len = sizeof(pkt);
pkt.type= 9;//debugging
pkt.crc=0;

pkt.crc=update_crc(pkt.len, pkt.crc);
pkt.crc=update_crc(pkt.type, pkt.crc);

for(i=0; i<pkt.len; i++){
if(write(input_stream, &buf[i], 1) != 1)
perror("write: ");
printf("Byte Value: %d\n",(uint8_t)buf[i]);
}

.



Relevant Pages

  • Re: Serial port communication - MSB is always set
    ... serial port on my embedded system that has an ... working with the correct baud rate being set. ... int setSerial(char *p_szPlatform, ... ///The code where I write to the serial port is as follows ...
    (comp.arch.embedded)
  • Serial port communication - MSB is always set
    ... serial port on my embedded system that has an ... working with the correct baud rate being set. ... int setSerial(char *p_szPlatform, ... ///The code where I write to the serial port is as follows ...
    (comp.arch.embedded)
  • Re: Serial port communication - MSB is always set
    ... serial port on my embedded system that has an ... int setSerial(char *p_szPlatform, ... ///The code where I write to the serial port is as follows ... The MSB is sent just ...
    (comp.arch.embedded)
  • serial ports and Linux (Slackware)
    ... Can anyone supply a suggestion for allowing a terminal ... (terminal program running outside) ... embedded system, and as it happens the embedded system will be based on ... connected to the system and again it will be using the serial port. ...
    (comp.os.linux.setup)
  • Re: serial ports and Linux (Slackware)
    ... (terminal program running outside) ... embedded system, and as it happens the embedded system will be based on ... Are you asking if you can run a serial console off the serial port on ... but I think you are talking about connecting a "dumb terminal" to the ...
    (comp.os.linux.setup)