58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
#ifndef CHAVIREMENT_H
|
|
#include "chavirement.h"
|
|
#endif
|
|
|
|
#include "Driver_GPIO.h"
|
|
#include "Driver_SPI.h"
|
|
#include "bordage.h"
|
|
|
|
int device_id = 0;
|
|
|
|
char lire(char address) {
|
|
//lit les données à l'adresse address
|
|
// couche protocolaire : bit MSB à 1 pour mode R
|
|
//on laisse MB par défaut à 0
|
|
char result = 0;
|
|
MyGPIO_Reset(GPIOA,8);
|
|
SPI_send( SPI1, (address | 1 << 7));
|
|
result = SPI_rcv(SPI1);
|
|
while(SPI1->SR & SPI_SR_BSY);
|
|
MyGPIO_Set(GPIOA,8);
|
|
return result;
|
|
}
|
|
|
|
|
|
void ecrire(char address, char data) {
|
|
MyGPIO_Reset(GPIOA,8);
|
|
SPI_send(SPI1, address) ;
|
|
SPI_send(SPI1, data);
|
|
while(SPI1->SR & SPI_SR_BSY);
|
|
MyGPIO_Set(GPIOA,8);
|
|
}
|
|
|
|
|
|
void chavirement_init(void){
|
|
//initialiser le SPI après init GPIO (fait dans le main)
|
|
|
|
//init matser spi1
|
|
SPI_init_master(SPI1) ;
|
|
|
|
//activer measure du power_ctl
|
|
//ecrire(0x2D, 1<<3);
|
|
device_id = (int) lire(0x0);
|
|
|
|
|
|
}
|
|
|
|
|
|
uint16_t chavirement_handler(void) {
|
|
uint8_t lsb = lire(0x34);
|
|
uint8_t msb = lire(0x35);
|
|
uint16_t value = ((msb << 8) + lsb);
|
|
|
|
if ((value<384)|| (value>640)) {
|
|
//appel fonction
|
|
Roulis_Handler();
|
|
}
|
|
return value;
|
|
}
|