Re: Serial port communication - MSB is always set
- From: ghelbig@xxxxxxxxx
- Date: Sun, 12 Aug 2007 07:37:00 -0000
On Aug 11, 5:11 pm, Affan <int...@xxxxxxxxx> wrote:
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 fromhttp://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]);
}
Are you absolutely certain that you have the size set properly? You
can get this if you have 7 bits, or if you set "ON" parity.
I would look at what actually got into the UCSRB & UCSRC registers
after initialization.
G.
.
- References:
- Serial port communication - MSB is always set
- From: Affan
- Serial port communication - MSB is always set
- Prev by Date: Re: MSP430 onchip flash programming documentation?
- Next by Date: Re: What's the difference between flash parameter blocks and main blocks?
- Previous by thread: Re: Serial port communication - MSB is always set
- Next by thread: I have a question about NAND flash interface.
- Index(es):
Relevant Pages
|