Fix reset: Pull nRESET down and then up.
authorWalter Fetter Lages <w.fetter@ieee.org>
Fri, 1 Feb 2019 06:54:34 +0000 (04:54 -0200)
committerWalter Fetter Lages <w.fetter@ieee.org>
Fri, 1 Feb 2019 06:54:34 +0000 (04:54 -0200)
lib/bno055_tty.c

index 2e4847b..3a8c463 100644 (file)
 #include <bno055_delay.h>
 #include <bno055_tty.h>
 
+#define        BUFFER_LEN 128
+
+#define BNO055_UART_START      0xaa
+#define BNO055_UART_WRITE_CMD  0x00
+#define BNO055_UART_READ_CMD   0x01
+#define BNO055_UART_ACK                0xee
+#define BNO055_UART_REPLY      0xbb
+
+#define BNO055_UART_SUCCESS    0x01
+
 s8 BNO055_tty_init(int fd,struct bno055_t *bno055)
 {
        struct termios tty;
+       int status;
        
        if(tcgetattr(fd,&tty)) return BNO055_ERROR;
         if(cfsetspeed(&tty,B115200)) return BNO055_OUT_OF_RANGE;
@@ -38,8 +49,15 @@ s8 BNO055_tty_init(int fd,struct bno055_t *bno055)
        tty.c_cflag|=CLOCAL;
         if(tcsetattr(fd,TCSANOW,&tty)) return BNO055_ERROR;
 
-       int status=TIOCM_DTR | TIOCM_RTS;
-        ioctl(fd,TIOCMBIC,&status);
+        /* nRESET low*/
+       status=TIOCM_DTR | TIOCM_RTS;
+       ioctl(fd,TIOCMBIS,&status);
+       usleep(1);
+       /* nRESET high */
+       status=TIOCM_DTR | TIOCM_RTS;
+       ioctl(fd,TIOCMBIC,&status);
+       /* Wait BNO055 Power on Reset time */
+       usleep(650000);
 
        bno055->bus_write=BNO055_tty_write;
        bno055->bus_read=BNO055_tty_read;
@@ -49,16 +67,6 @@ s8 BNO055_tty_init(int fd,struct bno055_t *bno055)
        return BNO055_SUCCESS;
 }
 
-#define        BUFFER_LEN 128
-
-#define BNO055_UART_START      0xaa
-#define BNO055_UART_WRITE_CMD  0x00
-#define BNO055_UART_READ_CMD   0x01
-#define BNO055_UART_ACK                0xee
-#define BNO055_UART_REPLY      0xbb
-
-#define BNO055_UART_SUCCESS    0x01
-
 s8 BNO055_tty_write(u8 dev_addr,u8 reg_addr,u8 *reg_data,u8 cnt)
 {
        u8 array[BUFFER_LEN];