From: Walter Fetter Lages Date: Sun, 27 Jan 2019 06:26:53 +0000 (-0200) Subject: Turn off hardware flow control. set nRESET to high. X-Git-Tag: f1~13 X-Git-Url: http://git.ece.ufrgs.br/?a=commitdiff_plain;h=6ad3754bace258d1ac191f659571ede327bebaaa;p=bno055.git Turn off hardware flow control. set nRESET to high. --- diff --git a/lib/bno055_tty.c b/lib/bno055_tty.c index 35ecbe6..1adfcc3 100644 --- a/lib/bno055_tty.c +++ b/lib/bno055_tty.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -32,8 +33,13 @@ s8 BNO055_tty_init(int fd,struct bno055_t *bno055) if(tcgetattr(fd,&tty)) return BNO055_ERROR; if(cfsetspeed(&tty,B115200)) return BNO055_OUT_OF_RANGE; cfmakeraw(&tty); + tty.c_cflag&=~CRTSCTS; + tty.c_cflag|=CLOCAL; if(tcsetattr(fd,TCSANOW,&tty)) return BNO055_ERROR; + int status=TIOCM_DTR | TIOCM_RTS; + ioctl(fd,TIOCMBIC,&status); + bno055->bus_write=BNO055_tty_write; bno055->bus_read=BNO055_tty_read; bno055->delay_msec=BNO055_tty_delay_ms; @@ -58,6 +64,7 @@ s8 BNO055_tty_write(u8 dev_addr,u8 reg_addr,u8 *reg_data,u8 cnt) u8 i=0; int n=0; + tcflush(dev_addr,TCIOFLUSH); array[0]=BNO055_UART_START; array[1]=BNO055_UART_WRITE_CMD; array[2]=reg_addr; @@ -69,7 +76,6 @@ s8 BNO055_tty_write(u8 dev_addr,u8 reg_addr,u8 *reg_data,u8 cnt) // Add a timeout? KISS approach for now... n=0; while(n < 2) if((n+=read(dev_addr,array+n,2-n))==-1) return BNO055_ERROR; - if(array[0] != BNO055_UART_ACK || array[1] != BNO055_UART_SUCCESS) return BNO055_ERROR; @@ -83,17 +89,17 @@ s8 BNO055_tty_read(u8 dev_addr,u8 reg_addr,u8 *reg_data,u8 cnt) int n=0; int length=0; + tcflush(dev_addr,TCIOFLUSH); array[0]=BNO055_UART_START; array[1]=BNO055_UART_READ_CMD; array[2]=reg_addr; array[3]=cnt; if(write(dev_addr,array,4)==-1) return BNO055_ERROR; - + // Add a timeout? KISS approach for now... n=0; while(n < 2) if((n+=read(dev_addr,array+n,2-n))==-1) return BNO055_ERROR; - switch(array[0]) { diff --git a/test/bno055_test.c b/test/bno055_test.c index f7dbe90..2820eef 100644 --- a/test/bno055_test.c +++ b/test/bno055_test.c @@ -9,7 +9,7 @@ void usage_help(const char *name) { - fprintf(stderr,"Usage: %s [-i i2c_address] [-t tty_device]\n",name); + fprintf(stderr,"Usage: %s -i i2c_address | -t tty_device\n",name); exit(EXIT_FAILURE); } @@ -52,7 +52,7 @@ int main(int argc,char *argv[]) case 't': /* TTY interface */ - if((fd=open(optarg,O_RDWR))==-1) + if((fd=open(optarg,O_RDWR | O_NOCTTY))==-1) { perror(argv[0]); return -errno;