64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
#ifndef CHAVIREMENT_H
|
|
#include "chavirement.h"
|
|
#endif
|
|
|
|
#include "Driver_GPIO.h"
|
|
#include "Driver_SPI.h"
|
|
#include "bordage.h"
|
|
|
|
int device_id = 0;
|
|
int16_t localvalue = 0;
|
|
uint8_t lsblocal = 0;
|
|
uint8_t msblocal = 0;
|
|
|
|
uint8_t 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);
|
|
}
|
|
|
|
|
|
void chavirement_handler(void) {
|
|
uint8_t msb = lire(0x37);
|
|
uint8_t lsb = lire(0x36);
|
|
int16_t value = 0;
|
|
//value |= (msb << 8);
|
|
value |= lsb;
|
|
localvalue = value;
|
|
lsblocal = lsb;
|
|
//msblocal = msb;
|
|
|
|
if (value < 185) {
|
|
//appel fonction
|
|
Roulis_Handler();
|
|
}
|
|
|
|
}
|