From d7e885244db13d4a0f1c9ff8ce0a824aa44ab749 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 24 Sep 2022 20:54:10 +0200 Subject: [PATCH] =?UTF-8?q?Quelques=20essais=20suppl=C3=A9mentaie,=20mais?= =?UTF-8?q?=20rien=20de=20concluant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gyro.c | 26 +++++++++++++++++++------- spi_nb.c | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/gyro.c b/gyro.c index 5e91c62..5b1f6a7 100644 --- a/gyro.c +++ b/gyro.c @@ -32,6 +32,7 @@ void Gyro_Init(void){ // Test de la présence du gyroscope : if(gyro_init_check()){ puts("Gyroscope non trouve"); + gyro_config(); }else{ puts("Gyroscope trouve"); gyro_config(); @@ -59,12 +60,23 @@ void gyro_config(){ // Xen : 1 uint16_t tampon[2] = {0x20, 0b11101111}; + uint8_t tampon2[10]="\0\0\0\0\0\0\0\0\0"; + int statu, nb_read; while(spi_nb_busy(spi0) == SPI_BUSY); cs_select(); int rep = spi_nb_write_data(spi0, tampon, 2); + if(rep == SPI_ERR_TRANSMIT_FIFO_FULL){ + printf("Erreur: spi_read_register: SPI_ERR_TRANSMIT_FIFO_FULL\n"); + //return statu; + } while(spi_nb_busy(spi0) == SPI_BUSY); cs_deselect(); + nb_read = spi_nb_read_data_8bits(spi0, tampon2); + printf("%d caracteres lus\n", nb_read); + + printf("tampon2 : %#4x %#4x %#4x\n", tampon2[0], tampon2[1], tampon2[2]); + if (rep == SPI_ERR_TRANSMIT_FIFO_FULL){ while(1){ printf("gyro_config: SPI_ERR_TRANSMIT_FIFO_FULL\n"); @@ -91,18 +103,13 @@ int gyro_read_register_blocking(uint8_t registrer, uint8_t *tampon, uint8_t nb_a } void Gyro_Read(uint16_t step_ms){ - uint8_t tampon[10]="123456789"; + uint8_t tampon[10]="\0\0\0\0\0\0\0\0\0"; + uint8_t tampon2[10]="ABCDEFGHI"; int16_t rot_x, rot_y, rot_z; static double angle_x=0, angle_y=0, angle_z=0; int nb_recu; - //cs_select(); - //while(spi_nb_read_register_8bits(spi0, 0x20, tampon, 1) == SPI_IN_PROGRESS); - //cs_deselect(); - gyro_read_register_blocking(0x20, tampon, 1); - //printf ("Gyro CTRL1 : %#4x\n", tampon[0] ); - spi_read_register(spi0, 0x20, tampon, 1); //printf ("Gyro CTRL1 (bis) : %#4x\n", tampon[1] ); @@ -114,6 +121,7 @@ void Gyro_Read(uint16_t step_ms){ //gyro_read_register_blocking(0x28, tampon, 6); spi_read_register(spi0, 0x28, tampon, 6); + for(int i=0; i<10; i++){ printf("%#4x ", tampon[i]); } @@ -128,5 +136,9 @@ void Gyro_Read(uint16_t step_ms){ printf("rx : %f, ry : %f, rz: %f\n", angle_x, angle_y, angle_z); + //while(spi_nb_busy(spi0)); + //spi_nb_read_data_8bits(spi0,tampon); + //printf("tampon : %s\n", tampon); + } \ No newline at end of file diff --git a/spi_nb.c b/spi_nb.c index 37296a3..0b4f5b3 100644 --- a/spi_nb.c +++ b/spi_nb.c @@ -146,7 +146,7 @@ void spi_nb_flush_recieve_fifo(spi_inst_t * spi){ uint8_t spi_nb_read_data_8bits(spi_inst_t * spi, uint8_t * buffer){ uint8_t index = 0; while(spi_get_hw(spi)->sr & SPI_SSPSR_RNE_BITS){ - buffer[index] = (uint8_t)spi_get_hw(spi)->dr & SPI_SSPDR_DATA_BITS; + buffer[index] = (uint8_t)spi_get_hw(spi)->dr ;//& SPI_SSPDR_DATA_BITS; index++; } return index;