lecture des deux capteurs simultanément
This commit is contained in:
parent
8dfe505a44
commit
a85c5b5c57
@ -21,6 +21,8 @@
|
|||||||
#define BUFFER_SIZE 0x1000
|
#define BUFFER_SIZE 0x1000
|
||||||
#define ERR_OK 0
|
#define ERR_OK 0
|
||||||
|
|
||||||
|
spi_inst_t * my_spi;
|
||||||
|
|
||||||
void SPI_beginTransaction(char my_ss_pin){
|
void SPI_beginTransaction(char my_ss_pin){
|
||||||
/* switch(my_ss_pin){
|
/* switch(my_ss_pin){
|
||||||
case D0: SPI.begin(SCK, MISO, MOSI, SS); break;
|
case D0: SPI.begin(SCK, MISO, MOSI, SS); break;
|
||||||
@ -28,6 +30,11 @@ void SPI_beginTransaction(char my_ss_pin){
|
|||||||
}*/
|
}*/
|
||||||
//
|
//
|
||||||
gpio_put(my_ss_pin, 0);
|
gpio_put(my_ss_pin, 0);
|
||||||
|
if(my_ss_pin == 1){
|
||||||
|
my_spi = spi0;
|
||||||
|
}else{
|
||||||
|
my_spi = spi1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +61,8 @@ uint8_t RdByte(
|
|||||||
tampon[0] = RegisterAdress >> 8 & 0x7F;
|
tampon[0] = RegisterAdress >> 8 & 0x7F;
|
||||||
tampon[1] = RegisterAdress & 0xFF;
|
tampon[1] = RegisterAdress & 0xFF;
|
||||||
|
|
||||||
spi_write_blocking(spi0, tampon, 2);
|
spi_write_blocking(my_spi, tampon, 2);
|
||||||
spi_read_blocking(spi0, 0x00, p_value, 1 );
|
spi_read_blocking(my_spi, 0x00, p_value, 1 );
|
||||||
|
|
||||||
//printf("RdByte 0x%02X%02X 0x%02X\n", tampon[0], tampon[1], *p_value);
|
//printf("RdByte 0x%02X%02X 0x%02X\n", tampon[0], tampon[1], *p_value);
|
||||||
|
|
||||||
@ -85,7 +92,7 @@ uint8_t WrByte(
|
|||||||
|
|
||||||
//printf("WrByte 0x%02X%02X 0x%02X\n", tampon[0], tampon[1], tampon[2]);
|
//printf("WrByte 0x%02X%02X 0x%02X\n", tampon[0], tampon[1], tampon[2]);
|
||||||
|
|
||||||
spi_write_blocking(spi0, tampon, 3);
|
spi_write_blocking(my_spi, tampon, 3);
|
||||||
|
|
||||||
SPI_endTransaction(my_ss_pin);
|
SPI_endTransaction(my_ss_pin);
|
||||||
|
|
||||||
@ -110,17 +117,17 @@ uint8_t WrMulti(
|
|||||||
|
|
||||||
tampon[0] = RegisterAdress >> 8 | 0x80;
|
tampon[0] = RegisterAdress >> 8 | 0x80;
|
||||||
tampon[1] = RegisterAdress & 0xFF;
|
tampon[1] = RegisterAdress & 0xFF;
|
||||||
spi_write_blocking(spi0, tampon, 2);
|
spi_write_blocking(my_spi, tampon, 2);
|
||||||
|
|
||||||
while(size > BUFFER_SIZE){
|
while(size > BUFFER_SIZE){
|
||||||
memcpy(my_buffer, (uint8_t*)&p_values[index], BUFFER_SIZE);
|
memcpy(my_buffer, (uint8_t*)&p_values[index], BUFFER_SIZE);
|
||||||
spi_write_blocking(spi0, my_buffer, BUFFER_SIZE);
|
spi_write_blocking(my_spi, my_buffer, BUFFER_SIZE);
|
||||||
size = size - BUFFER_SIZE;
|
size = size - BUFFER_SIZE;
|
||||||
index = index + BUFFER_SIZE;
|
index = index + BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
if(size > 0){
|
if(size > 0){
|
||||||
memcpy(my_buffer, (uint8_t*)&p_values[index], size);
|
memcpy(my_buffer, (uint8_t*)&p_values[index], size);
|
||||||
spi_write_blocking(spi0, my_buffer, size);
|
spi_write_blocking(my_spi, my_buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_endTransaction(my_ss_pin);
|
SPI_endTransaction(my_ss_pin);
|
||||||
@ -147,19 +154,19 @@ uint8_t RdMulti(
|
|||||||
tampon[0] = RegisterAdress >> 8 & 0x7F;
|
tampon[0] = RegisterAdress >> 8 & 0x7F;
|
||||||
tampon[1] = RegisterAdress & 0xFF;
|
tampon[1] = RegisterAdress & 0xFF;
|
||||||
|
|
||||||
spi_write_blocking(spi0, tampon, 2);
|
spi_write_blocking(my_spi, tampon, 2);
|
||||||
spi_read_blocking(spi0, 0, p_values, size);
|
spi_read_blocking(my_spi, 0, p_values, size);
|
||||||
|
|
||||||
//printf("RdMulti 0x%02X%02X size : 0x%02X\n", tampon[0], tampon[1], size);
|
//printf("RdMulti 0x%02X%02X size : 0x%02X\n", tampon[0], tampon[1], size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
while(size > buffer_size){
|
while(size > buffer_size){
|
||||||
spi_read_blocking(spi0, 0, &(p_values[index]), buffer_size);
|
spi_read_blocking(my_spi, 0, &(p_values[index]), buffer_size);
|
||||||
index += buffer_size;
|
index += buffer_size;
|
||||||
size -= buffer_size;
|
size -= buffer_size;
|
||||||
}
|
}
|
||||||
if(size > 0){
|
if(size > 0){
|
||||||
spi_read_blocking(spi0, 0, &(p_values[index]), size);
|
spi_read_blocking(my_spi, 0, &(p_values[index]), size);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
42
main.c
42
main.c
@ -50,7 +50,7 @@ float distance1_mm=0, distance2_mm=0;
|
|||||||
extern float abscisse;
|
extern float abscisse;
|
||||||
extern struct point_xyo_t point;
|
extern struct point_xyo_t point;
|
||||||
float vitesse;
|
float vitesse;
|
||||||
VL53L8CX_Configuration Dev;
|
VL53L8CX_Configuration gauche, droit;
|
||||||
|
|
||||||
uint8_t capteur_init(VL53L8CX_Configuration * capteur);
|
uint8_t capteur_init(VL53L8CX_Configuration * capteur);
|
||||||
|
|
||||||
@ -81,11 +81,16 @@ void main(void)
|
|||||||
gpio_set_dir(LED1PIN, GPIO_OUT );
|
gpio_set_dir(LED1PIN, GPIO_OUT );
|
||||||
gpio_put(LED1PIN, 1);
|
gpio_put(LED1PIN, 1);
|
||||||
|
|
||||||
// Initialisation de la liaison SPI
|
// Initialisation de la liaison SPI0
|
||||||
gpio_set_function(2, GPIO_FUNC_SPI);
|
gpio_set_function(2, GPIO_FUNC_SPI);
|
||||||
gpio_set_function(3, GPIO_FUNC_SPI);
|
gpio_set_function(3, GPIO_FUNC_SPI);
|
||||||
gpio_set_function(4, GPIO_FUNC_SPI);
|
gpio_set_function(4, GPIO_FUNC_SPI);
|
||||||
|
|
||||||
|
// Initialisation de la liaison SPI1
|
||||||
|
gpio_set_function(26, GPIO_FUNC_SPI);
|
||||||
|
gpio_set_function(27, GPIO_FUNC_SPI);
|
||||||
|
gpio_set_function(28, GPIO_FUNC_SPI);
|
||||||
|
|
||||||
gpio_set_function(16, GPIO_FUNC_NULL);
|
gpio_set_function(16, GPIO_FUNC_NULL);
|
||||||
gpio_set_function(17, GPIO_FUNC_NULL);
|
gpio_set_function(17, GPIO_FUNC_NULL);
|
||||||
gpio_set_function(18, GPIO_FUNC_NULL);
|
gpio_set_function(18, GPIO_FUNC_NULL);
|
||||||
@ -95,11 +100,20 @@ void main(void)
|
|||||||
gpio_set_dir(1, GPIO_OUT );
|
gpio_set_dir(1, GPIO_OUT );
|
||||||
gpio_put(1, 1);
|
gpio_put(1, 1);
|
||||||
|
|
||||||
Dev.platform.address = 1;
|
gpio_init(29); // CS
|
||||||
|
gpio_set_dir(29, GPIO_OUT );
|
||||||
|
gpio_put(29, 1);
|
||||||
|
|
||||||
|
|
||||||
|
gauche.platform.address = 1;
|
||||||
|
droit.platform.address = 29;
|
||||||
|
|
||||||
spi_set_format(spi0, 8, SPI_CPOL_1, SPI_CPHA_1, SPI_MSB_FIRST);
|
spi_set_format(spi0, 8, SPI_CPOL_1, SPI_CPHA_1, SPI_MSB_FIRST);
|
||||||
spi_init(spi0, 2000000);
|
spi_init(spi0, 2000000);
|
||||||
|
|
||||||
|
spi_set_format(spi1, 8, SPI_CPOL_1, SPI_CPHA_1, SPI_MSB_FIRST);
|
||||||
|
spi_init(spi1, 2000000);
|
||||||
|
|
||||||
tampon[0] = 0x55;
|
tampon[0] = 0x55;
|
||||||
tampon[1] = 0x55;
|
tampon[1] = 0x55;
|
||||||
|
|
||||||
@ -200,22 +214,26 @@ void capteurs_affiche_donnees(VL53L8CX_ResultsData * results_gauche, VL53L8CX_Re
|
|||||||
|
|
||||||
float planche_pos_x, planche_pos_y;
|
float planche_pos_x, planche_pos_y;
|
||||||
void gestion_VL53L8CX(void){
|
void gestion_VL53L8CX(void){
|
||||||
VL53L8CX_ResultsData Results;
|
VL53L8CX_ResultsData results_gauche, results_droit;
|
||||||
float distance_obstacle;
|
float distance_obstacle;
|
||||||
capteur_init(&Dev);
|
capteur_init(&gauche);
|
||||||
|
capteur_init(&droit);
|
||||||
sleep_ms(100);
|
sleep_ms(100);
|
||||||
capteur_actualise( &Dev, &Results); // une première lecture
|
capteur_actualise( &gauche, &results_gauche); // une première lecture
|
||||||
|
capteur_actualise( &droit, &results_droit); // une première lecture
|
||||||
uint8_t status, isReady;
|
uint8_t status, isReady;
|
||||||
while(1){
|
while(1){
|
||||||
isReady = capteur_actualise( &Dev, &Results);
|
isReady = 0;
|
||||||
|
isReady |= capteur_actualise( &gauche, &results_gauche);
|
||||||
|
isReady |= capteur_actualise( &droit, &results_droit);
|
||||||
if(isReady){
|
if(isReady){
|
||||||
capteurs_affiche_donnees(&Results, &Results);
|
capteurs_affiche_donnees(&results_gauche, &results_droit);
|
||||||
//VL53L8_lecture( &Dev, &Results);
|
//VL53L8_lecture( &gauche, &Results);
|
||||||
VL53L8_min_distance(Results, &distance_obstacle);
|
VL53L8_min_distance(results_gauche, &distance_obstacle);
|
||||||
VL53L8_pos_planche(Results, &planche_pos_x, &planche_pos_y);
|
VL53L8_pos_planche(results_gauche, &planche_pos_x, &planche_pos_y);
|
||||||
}
|
}
|
||||||
//affichage();
|
//affichage();
|
||||||
sleep_ms(50);
|
sleep_ms(150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user