Compare commits
24 commits
main
...
Accelerome
| Author | SHA1 | Date | |
|---|---|---|---|
| 63fc720afa | |||
| c9adc36066 | |||
| 6add9ea143 | |||
| f7f7c1b987 | |||
| a4ee0a2cf8 | |||
| d75491ac45 | |||
| 8c08fd4ffc | |||
| 5a4457b61e | |||
| 31c72fd5f6 | |||
| 5f4ed0902c | |||
| 4e3e11aab2 | |||
| d7b6391cd6 | |||
| 6dc2bc093c | |||
| 82f61ffcde | |||
| 5d6e9ccd85 | |||
| 03898d3d1c | |||
| a2cb5212c7 | |||
| 7e8a278228 | |||
| c371352520 | |||
| ee23278a02 | |||
| 0bad25a87c | |||
| 9a74614b25 | |||
| b93583d501 | |||
| b67a2ae4ea |
14 changed files with 514 additions and 1 deletions
140
Accelerometre.c
Normal file
140
Accelerometre.c
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#include <Horloge.h>
|
||||||
|
#include <MYGPIO.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <MySPI.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
//Pin GPIOA_9 et GPIOA_10 sont pris par USART
|
||||||
|
|
||||||
|
/*
|
||||||
|
I2C SDA IN/OUT
|
||||||
|
I2C SCL OUT
|
||||||
|
*/
|
||||||
|
|
||||||
|
//il faut recuperer le data qui sort
|
||||||
|
|
||||||
|
/*
|
||||||
|
SPI1_NSS PA4 - Utilisé
|
||||||
|
NSS = 0 -> slave active
|
||||||
|
NSS = 1 -> slave inactive
|
||||||
|
|
||||||
|
SPI1_SCK PA5
|
||||||
|
SPI1_MISO PA6
|
||||||
|
SPI1_MOSI PA7
|
||||||
|
|
||||||
|
TIM3 CH3 PB0
|
||||||
|
|
||||||
|
0x32 50 DATAX0 R 00000000 X-Axis Data 0
|
||||||
|
0x33 51 DATAX1 R 00000000 X-Axis Data 1
|
||||||
|
0x34 52 DATAY0 R 00000000 Y-Axis Data 0
|
||||||
|
0x35 53 DATAY1 R 00000000 Y-Axis Data 1
|
||||||
|
0x36 54 DATAZ0 R 00000000 Z-Axis Data 0
|
||||||
|
0x37 55 DATAZ1 R 00000000 Z-Axis Data 1
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void initAccelo(void)
|
||||||
|
{
|
||||||
|
MySPI_Init(SPI1);
|
||||||
|
// Power_CTL register = 0x2D ? write 0x08 (MEASURE = 1)
|
||||||
|
MySPI_Clear_NSS();
|
||||||
|
MySPI_Send(0x2D & 0x3F); // write address (no read bit!)
|
||||||
|
MySPI_Send(0x08); // set MEASURE bit
|
||||||
|
MySPI_Set_NSS();
|
||||||
|
|
||||||
|
for (volatile int i = 0; i < 10000; i++); // small delay
|
||||||
|
}
|
||||||
|
|
||||||
|
// send bits, les bits inclus en char envoyés: RW MB A5 A4 A3 A2 A1 A0
|
||||||
|
//RW: R = 1 et W = 0
|
||||||
|
//MB à 1 veut measurement et MB à 0 Standby
|
||||||
|
uint16_t * RecupAccelo(void){ //Renvoie 48 bits en forme des chars
|
||||||
|
static uint16_t Messias[3];
|
||||||
|
|
||||||
|
//On lit X0
|
||||||
|
MySPI_Clear_NSS();//Mettre la broche PA4 à 0
|
||||||
|
MySPI_Send(0x80|0x00|0x32); //Lecture de X0 et MB à 1 pour garder les valeurs 0b11110010: (R/W|MB|Adress)
|
||||||
|
//Faktisk dritsmart det katten gjør, setter MB=1 som sier multiple byte read, så leser den alle 6 bytes samtidig istedenfor en og en
|
||||||
|
uint16_t X0 = MySPI_Read();
|
||||||
|
MySPI_Set_NSS(); //Mettre la broche PA4 à 1
|
||||||
|
|
||||||
|
//On lit X1
|
||||||
|
MySPI_Clear_NSS();//Mettre la broche PA4 à 0
|
||||||
|
MySPI_Send(0x80|0x00|0x33); //Lecture de X1
|
||||||
|
Messias[0] = X0 | (MySPI_Read() << 8);
|
||||||
|
MySPI_Set_NSS(); //Mettre la broche PA4 à 1
|
||||||
|
|
||||||
|
//On lit Y0
|
||||||
|
MySPI_Clear_NSS();//Mettre la broche PA4 à 0
|
||||||
|
MySPI_Send(0x80|0x00|0x34); //Lecture de Y0
|
||||||
|
uint16_t Y0 = MySPI_Read();
|
||||||
|
MySPI_Set_NSS(); //Mettre la broche PA4 à 1
|
||||||
|
|
||||||
|
//On lit Y1
|
||||||
|
MySPI_Clear_NSS();//Mettre la broche PA4 à 0
|
||||||
|
MySPI_Send(0x80|0x00|0x35); //Lecture de Y1
|
||||||
|
Messias[1] = Y0 | (MySPI_Read() << 8);
|
||||||
|
MySPI_Set_NSS(); //Mettre la broche PA4 à 1
|
||||||
|
|
||||||
|
//On lit Z0
|
||||||
|
MySPI_Clear_NSS();//Mettre la broche PA4 à 0
|
||||||
|
MySPI_Send(0x80|0x00|0x36); //Lecture de Z0
|
||||||
|
uint16_t Z0 = MySPI_Read();
|
||||||
|
MySPI_Set_NSS(); //Mettre la broche PA4 à 1
|
||||||
|
|
||||||
|
//On lit Z1
|
||||||
|
MySPI_Clear_NSS();//Mettre la broche PA4 à 0
|
||||||
|
MySPI_Send(0x80|0x00|0x37); //Lecture de Z1
|
||||||
|
Messias[2] = Z0 | (MySPI_Read() << 8);
|
||||||
|
MySPI_Set_NSS(); //Mettre la broche PA4 à 1
|
||||||
|
|
||||||
|
return Messias;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t * KattRecupAccelo(void) //Beaucoup plus smart
|
||||||
|
{
|
||||||
|
static uint16_t Messias[3];
|
||||||
|
uint8_t buf[6];
|
||||||
|
// Multi-byte read from 0x32 (X0..Z1)
|
||||||
|
MySPI_Clear_NSS();
|
||||||
|
// Send READ + MB + address
|
||||||
|
MySPI_Send(0x80 | 0x40 | 0x32); // 0xF2
|
||||||
|
// Read 6 sequential registers
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
buf[i] = (uint8_t)MySPI_Read();
|
||||||
|
}
|
||||||
|
MySPI_Set_NSS();
|
||||||
|
// Convert little-endian to 16-bit signed values
|
||||||
|
Messias[0] = (uint16_t)(buf[1] << 8 | buf[0]); // X
|
||||||
|
Messias[1] = (uint16_t)(buf[3] << 8 | buf[2]); // Y
|
||||||
|
Messias[2] = (uint16_t)(buf[5] << 8 | buf[4]); // Z
|
||||||
|
|
||||||
|
return Messias;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initLacheur(void){
|
||||||
|
GPIOB->CRH &= ~(0xF << (0 * 4));
|
||||||
|
GPIOB->CRH |= (0xA << (0 * 4)); //On met GPIOB.8 en mode output 2Mhz, alternate pp
|
||||||
|
Timer_Init(TIM4, 20000 - 1, 71); //Claire m'a aidé
|
||||||
|
}
|
||||||
|
|
||||||
|
//Recuperer le DATA en X, Z, Y
|
||||||
|
void LacheVoile(uint16_t * DATA){
|
||||||
|
//uint16_t X = DATA[0]; //Z le longe du mât (masten)
|
||||||
|
//uint16_t Z = DATA[2];// //X le long du sense de voilier
|
||||||
|
uint16_t Y = DATA[1]; ////Y vers les bords (Tribord/Babord)
|
||||||
|
if (Y>=0x007B){// exatement à 40 degrés, on lache le 40%. 0xFF*(40deg/90deg)
|
||||||
|
//Le PWM du moteur est gère par PB7
|
||||||
|
MyTimer_PWM(TIM4, 3); //TIM4 CH3 pour PB8
|
||||||
|
Set_DutyCycle_PWM(TIM4, 3, 2); //On met Duty cycle à 2% et il reste autour de 90 deg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
8
Accelerometre.h
Normal file
8
Accelerometre.h
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void initAccelo(void);
|
||||||
|
uint16_t * RecupAccelo(void);
|
||||||
|
void LacheVoile(uint16_t * DATA);
|
||||||
|
void initLacheur(void);
|
||||||
|
uint16_t * KattRecupAccelo(void);
|
||||||
159
Horloge.c
Normal file
159
Horloge.c
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <Horloge.h>
|
||||||
|
|
||||||
|
|
||||||
|
//Il faut trouver le signal
|
||||||
|
//On est à Timer 2
|
||||||
|
|
||||||
|
static void (*TIM2_Appel)(void) = 0;
|
||||||
|
|
||||||
|
void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler){
|
||||||
|
if (Timer == TIM1) {
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; //L'horloge est enabléd
|
||||||
|
} else if (Timer == TIM2) {
|
||||||
|
TIM2->CR1 |= TIM_CR1_CEN; //On enable l'horloge interne
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||||
|
} else if (Timer == TIM3) {
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||||
|
} else if (Timer == TIM4) {
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
||||||
|
}
|
||||||
|
Timer->ARR |= Autoreload;
|
||||||
|
Timer->PSC |= Prescaler;
|
||||||
|
}
|
||||||
|
|
||||||
|
//La fonction TIM2_IRQHandler s'utilise dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR
|
||||||
|
void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source
|
||||||
|
if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow
|
||||||
|
TIM2->SR &= ~TIM_SR_UIF; //Remise à zero
|
||||||
|
|
||||||
|
if (TIM2_Appel){TIM2_Appel();}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void)){ //On veut créer une fonction qui envoie un signal au cas où il y a debordement, avec une prioritaire, 0 plus importante 15 moins importante
|
||||||
|
if (Timer == TIM2){
|
||||||
|
|
||||||
|
TIM2_Appel = Interrupt_fonc;
|
||||||
|
|
||||||
|
NVIC_EnableIRQ(TIM2_IRQn);
|
||||||
|
NVIC_SetPriority(TIM2_IRQn, Prio);
|
||||||
|
TIM2->DIER |= TIM_DIER_UIE; //Le registre DIER(Interrupt Enable Register) est mis au bit Update Interrupt, qui se commute lors d'un overflow
|
||||||
|
TIM2->CR1 |= TIM_CR1_CEN; //Clock Enable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Fonction qui permet de clignoter le DEL à un pulse volue (Sinusoïdale)
|
||||||
|
//Si le sinus est haut(haute tension) le Duty Cicle est proche de 100%,
|
||||||
|
//si le sinus est bas (vers la tension la plus basse) le Duty Cycle est vers 0%
|
||||||
|
//On s'applique sur un plage de [0V; 3.3V]
|
||||||
|
|
||||||
|
|
||||||
|
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
||||||
|
int pwrmd;
|
||||||
|
#if POWERMODE //Powermode 1
|
||||||
|
pwrmd = 0b110;
|
||||||
|
#else
|
||||||
|
pwrmd = 0b111; //Powermode 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (Channel == 1){
|
||||||
|
Timer->CCMR1 &= ~(0b111<<4); //On clear les trois bits qui sont de pwm
|
||||||
|
Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur
|
||||||
|
Timer->CCMR1 |= TIM_CCMR1_OC1PE; //Update preload, il n'affecte pas le valeur avant que la prochaine cycle
|
||||||
|
Timer->CCER = TIM_CCER_CC1E; //Enable le pin voulu basculer
|
||||||
|
}
|
||||||
|
else if (Channel == 2){
|
||||||
|
Timer->CCMR1 &= ~(0b111<<12); //Le TIMx_CCMR1 configure deux channels, de bit [6:4] CH1, [14:12] CH2 (OC2M = Output Channel 2 )
|
||||||
|
Timer->CCMR1 |= (pwrmd<<12);
|
||||||
|
Timer->CCMR1 |= TIM_CCMR1_OC2PE;
|
||||||
|
Timer->CCER |= TIM_CCER_CC2E;
|
||||||
|
}
|
||||||
|
else if (Channel == 3){
|
||||||
|
Timer->CCMR1 &= ~(0b111<<4);
|
||||||
|
Timer->CCMR2 |= (pwrmd<<4);
|
||||||
|
Timer->CCMR2 |= TIM_CCMR2_OC3PE;
|
||||||
|
Timer->CCER |= TIM_CCER_CC3E;
|
||||||
|
}
|
||||||
|
else if (Channel == 4){
|
||||||
|
Timer->CCMR1 &= ~(0b111<<12);
|
||||||
|
Timer->CCMR2 |= (pwrmd<<12);
|
||||||
|
Timer->CCMR2 |= TIM_CCMR2_OC4PE;
|
||||||
|
Timer->CCER |= TIM_CCER_CC4E;
|
||||||
|
}
|
||||||
|
|
||||||
|
//En dessous d'ici, on a l'aide du plus gentil chat que je connais
|
||||||
|
// Enable auto-reload preload -- //Ensures that your initial configuration — PWM mode, duty cycle, period — actually takes effect before the timer starts counting.
|
||||||
|
Timer->CR1 |= TIM_CR1_ARPE;
|
||||||
|
// Force update event to load ARR and CCR values immediately
|
||||||
|
Timer->EGR |= TIM_EGR_UG;
|
||||||
|
// Start the timer
|
||||||
|
Timer->CR1 |= TIM_CR1_CEN;
|
||||||
|
|
||||||
|
switch (Channel) {
|
||||||
|
case 1:
|
||||||
|
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<0*4); GPIOA->CRH |= (0xA<<0*4); TIM1->BDTR |= 1<<15; }
|
||||||
|
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<0*4); GPIOA->CRL |= (0xA<<0*4);}
|
||||||
|
if (Timer == TIM3){GPIOA->CRL &= ~(0xF<<6*4); GPIOA->CRL |= (0xA<<6*4);}
|
||||||
|
if (Timer == TIM4){GPIOB->CRL &= ~(0xF<<5*4); GPIOB->CRL |= (0xA<<5*4);}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<1*4); GPIOA->CRL |= (0xA<<1*4); TIM1->BDTR |= 1<<15;}
|
||||||
|
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<1*4); GPIOA->CRL |= (0xA<<1*4);}
|
||||||
|
if (Timer == TIM3){GPIOA->CRL &= ~(0xF<<7*4); GPIOA->CRL |= (0xA<<7*4);}
|
||||||
|
if (Timer == TIM4){GPIOB->CRL &= ~(0xF<<7*4); GPIOB->CRL |= (0xA<<7*4);}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<2*4); GPIOA->CRH |= (0xA<<2*4); TIM1->BDTR |= 1<<15;}
|
||||||
|
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<2*4); GPIOA->CRL |= (0xA<<2*4);}
|
||||||
|
if (Timer == TIM3){GPIOB->CRL &= ~(0xF<<0*4); GPIOB->CRL |= (0xA<<0*4);}
|
||||||
|
if (Timer == TIM4){GPIOB->CRH &= ~(0xF<<0*4); GPIOB->CRH |= (0xA<<0*4);}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (Timer == TIM1){GPIOA->CRH &= ~(0xF<<3*4); GPIOA->CRH |= (0xA<<3*4); TIM1->BDTR |= 1<<15;}
|
||||||
|
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<3*4); GPIOA->CRL |= (0xA<<3*4);}
|
||||||
|
if (Timer == TIM3){GPIOB->CRL &= ~(0xF<<1*4); GPIOB->CRL |= (0xA<<1*4);}
|
||||||
|
if (Timer == TIM4){GPIOB->CRH &= ~(0xF<<1*4); GPIOB->CRH |= (0xA<<1*4);}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Une fonction qui met le bon PWM volue
|
||||||
|
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC){
|
||||||
|
int CCR_VAL = (ARR_VAL + 1) * DutyC / 100; //ARR_VAL déjà definie
|
||||||
|
switch (Channel){
|
||||||
|
case 1: Timer->CCR1 = CCR_VAL;
|
||||||
|
case 2: Timer->CCR2 = CCR_VAL;
|
||||||
|
case 3: Timer->CCR3 = CCR_VAL;
|
||||||
|
case 4: Timer->CCR4 = CCR_VAL;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
Timer->EGR |= TIM_EGR_UG;
|
||||||
|
}
|
||||||
|
//Putaing con, ça marche pas
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Pulse width modulation mode allows you to generate a signal with a frequency determined
|
||||||
|
by the value of the TIMx_ARR register and a duty cycle determined by the value of the
|
||||||
|
TIMx_CCRx register.
|
||||||
|
|
||||||
|
The PWM mode can be selected independently on each channel (one PWM per OCx
|
||||||
|
output) by writing 110 (PWM mode 1) or ‘111 (PWM mode 2) in the OCxM bits in the
|
||||||
|
TIMx_CCMRx register. You must enable the corresponding preload register by setting the
|
||||||
|
OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register by
|
||||||
|
setting the ARPE bit in the TIMx_CR1 register.
|
||||||
|
*/
|
||||||
|
//Il faut créer une autre fonction qui lui met le bon duty cycle
|
||||||
|
//Timer->CCR1 = Duty_cycle*0.01*3.3; // On divise par cent et multiplue par 3.3V, plage de ADC
|
||||||
|
|
||||||
|
//Pareil pour la frequence, faut une fonction externe qui lui fait ça
|
||||||
|
|
||||||
|
|
||||||
|
//Pendant les vacances terminer l'ADC et l'USART (Activités sur Moodle)
|
||||||
|
//Hell naw, that did not happen cuh
|
||||||
|
|
||||||
16
Horloge.h
Normal file
16
Horloge.h
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#define PSC_VAL 624
|
||||||
|
#define ARR_VAL 0xE0FF
|
||||||
|
|
||||||
|
//DUTY CYCLE
|
||||||
|
#define DUTYC 70 //Chiffre entre 0 et 100, où 100 est 100% duty cycle
|
||||||
|
#define POWERMODE 1 // 1 vaut powermode 1, 0 vaut powermode 2 (Powermode pour le config de dutycycle)
|
||||||
|
//Powermode 1 reste sur la bonne polarité: cad. si DUTY_CYCLE vaut 60 alors le signal reste HIGH pour 60% du periode, inverse pour pwmd2
|
||||||
|
//Timer
|
||||||
|
void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler);
|
||||||
|
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void));
|
||||||
|
void TIM2_IRQHandler(void);
|
||||||
|
|
||||||
|
//PWM
|
||||||
|
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel);
|
||||||
|
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC);
|
||||||
BIN
IMAGES/Carte_Nucleo_pins.png
Normal file
BIN
IMAGES/Carte_Nucleo_pins.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
BIN
IMAGES/Channel_for_servo.png
Normal file
BIN
IMAGES/Channel_for_servo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.3 KiB |
BIN
IMAGES/Measure_Bit_Standby.png
Normal file
BIN
IMAGES/Measure_Bit_Standby.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
BIN
IMAGES/RegisterMap_SPI.png
Normal file
BIN
IMAGES/RegisterMap_SPI.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 196 KiB |
BIN
IMAGES/Standby_PWCTL.png
Normal file
BIN
IMAGES/Standby_PWCTL.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
3
Informations_Generales/README.md
Normal file
3
Informations_Generales/README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Notre RegisterMap
|
||||||
|
|
||||||
|

|
||||||
BIN
Lib_Com_Periph_2022.lib
Normal file
BIN
Lib_Com_Periph_2022.lib
Normal file
Binary file not shown.
129
MySPI.h
Normal file
129
MySPI.h
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
|
||||||
|
#ifndef INC_MYSPI_H_
|
||||||
|
#define INC_MYSPI_H_
|
||||||
|
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
/*************************************************************************************
|
||||||
|
===================== By Periph team INSA GEI 2022 ===========================
|
||||||
|
*************************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*************************************************************************************
|
||||||
|
===================== I2C les IO STM32F103 =================================
|
||||||
|
*************************************************************************************
|
||||||
|
Les IO sont pris en charge par la lib, pas besoin de faire les configurations
|
||||||
|
|
||||||
|
|
||||||
|
Sur la Nucléo , le SPI1 est perturbé par la LED2 (PA5), mais doit pouvoir subir les front SCK qd même (LED clignote vite..)
|
||||||
|
le SPI2 n'est pas utilisable car pin non connectées par défaut (sauf à modifier les SB). En fait la Nucléo fait un choix entre SPI1
|
||||||
|
et SPI2 par soudage jumper (SB).
|
||||||
|
|
||||||
|
-> Utiliser SPI1 avec la carte Nucléo
|
||||||
|
|
||||||
|
* **IO SPI 1**
|
||||||
|
SPI1_NSS PA4
|
||||||
|
SPI1_SCK PA5
|
||||||
|
SPI1_MISO PA6
|
||||||
|
SPI1_MOSI PA7
|
||||||
|
|
||||||
|
**IO SPI 2**
|
||||||
|
SPI2_NSS PB12
|
||||||
|
SPI2_SCK PB13
|
||||||
|
SPI2_MISO PB14
|
||||||
|
SPI2_MOSI PB15
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*************************************************************************************
|
||||||
|
==================== Fondamentaux SPI ==========================================
|
||||||
|
*************************************************************************************
|
||||||
|
- Bus Synchrone, 4 fils (même si on peut l'utiliser en 3 fils)
|
||||||
|
- Transfert à l'octet
|
||||||
|
- Protocole entre un Master (contrôle SCK) et un Slave
|
||||||
|
- SCK permet de synchroniser les bits de chaque octet. Il se configure par :
|
||||||
|
* son niveau de repos : ici niveau '1'
|
||||||
|
* le front actif de synchronisation pour chaque bit : ici front montant (front up durant bit stable)
|
||||||
|
- /CS ou /NSS active le slave sur l'état bas
|
||||||
|
- MOSI : Master Out Slave In (donc data circulant du Master vers le Slave, donc écriture dans le Slave)
|
||||||
|
- MISO : Master In Slave Out (donc data circulant du Slave vers le Master, donc lecture du Slave)
|
||||||
|
|
||||||
|
Bien que la lib propose une fonction d'écriture et de lecture :
|
||||||
|
* une écriture s'accompagne obligatoirement d'une lecture (bidon)
|
||||||
|
* une lecture s'accompagne obligatoirement d'une écriture (bidon)
|
||||||
|
La gestion /CS = /NSS se fait "à la main". On peut alors lire toute une série d'octets
|
||||||
|
en laissant /CS à l'état bas pendant toute la durée de circulation des octets.
|
||||||
|
|
||||||
|
|
||||||
|
*************************************************************************************
|
||||||
|
==================== La lib SPI ==========================================
|
||||||
|
*************************************************************************************
|
||||||
|
|
||||||
|
fonctions essentielles :
|
||||||
|
|
||||||
|
MySPI_Init
|
||||||
|
MySPI_Send
|
||||||
|
MySPI_Read
|
||||||
|
MySPI_Set_NSS
|
||||||
|
MySPI_Clear_NSS
|
||||||
|
|
||||||
|
|
||||||
|
==========================================================================================*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*=========================================================================================
|
||||||
|
INITIALISATION SPI
|
||||||
|
========================================================================================= */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configure le SPI spécifié : FSCK = 281kHz, Repos SCK = '1', Front actif = up
|
||||||
|
Gestion /CS logicielle à part, configure les 4 IO
|
||||||
|
- SCK, MOSI : Out Alt push pull
|
||||||
|
- MISO : floating input
|
||||||
|
- /NSS (/CS) : Out push pull
|
||||||
|
* @param SPI_TypeDef * SPI : SPI1 ou SPI2
|
||||||
|
*/
|
||||||
|
void MySPI_Init(SPI_TypeDef * SPI);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Envoie un octet (/CS non géré, à faire logiciellement)
|
||||||
|
Plus en détail, émission de l'octet souhaité sur MOSI
|
||||||
|
Lecture en même temps d'un octet poubelle sur MISO (non exploité)
|
||||||
|
* @param : char ByteToSend : l'octet à envoyer
|
||||||
|
*/
|
||||||
|
void MySPI_Send(char ByteToSend);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reçoit un octet (/CS non géré, à faire logiciellement)
|
||||||
|
Plus en détail, émission d'un octet bidon sur MOSI (0x00)
|
||||||
|
pour élaborer les 8 fronts sur SCK et donc piloter le slave en lecture
|
||||||
|
qui répond sur MISO
|
||||||
|
* @param : none
|
||||||
|
* @retval : l'octet lu.
|
||||||
|
*/
|
||||||
|
char MySPI_Read(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Positionne /CS = /NSS à '1'. A utiliser pour borner les octets à transmettre/recevoir
|
||||||
|
* @param : none
|
||||||
|
*/
|
||||||
|
void MySPI_Set_NSS(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Positionne /CS = /NSS à '0'. A utiliser pour borner les octets à transmettre/recevoir
|
||||||
|
* @param :none
|
||||||
|
*/
|
||||||
|
void MySPI_Clear_NSS(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -8,6 +8,10 @@ Bem vindo ao projeto veleiro de µcontroladores 4AE-SE 2025.
|
||||||
|
|
||||||
Welkom bij het microcontroller zeilbootproject 4AE-SE 2025.
|
Welkom bij het microcontroller zeilbootproject 4AE-SE 2025.
|
||||||
|
|
||||||
|
##Le Navire actuellement
|
||||||
|
|
||||||
|
Actuellement la navire lâche les voiles dès qu'on a un "vent" trop fort.
|
||||||
|
|
||||||
##Les groupes et résponsabilités sont :
|
##Les groupes et résponsabilités sont :
|
||||||
>>Nicolas et Jarno : Envoi de UART et PWM dans la bonne fréquence (canal), pour relier le voilier à l'ecran.
|
>>Nicolas et Jarno : Envoi de UART et PWM dans la bonne fréquence (canal), pour relier le voilier à l'ecran.
|
||||||
|
|
||||||
|
|
@ -22,5 +26,6 @@ Welkom bij het microcontroller zeilbootproject 4AE-SE 2025.
|
||||||
|
|
||||||
License : CC-BY-NC-SA 4.0
|
License : CC-BY-NC-SA 4.0
|
||||||
|
|
||||||
|
>>Register Map pour la SPI
|
||||||
|

|
||||||
|
|
||||||
|
|
|
||||||
53
principal.c
Normal file
53
principal.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#include <stm32f10x.h>
|
||||||
|
#include <Horloge.h>
|
||||||
|
#include <MYGPIO.h>
|
||||||
|
#include <MySPI.h>
|
||||||
|
#include <Accelerometre.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t * Melding;
|
||||||
|
volatile uint16_t X;
|
||||||
|
volatile uint16_t Y;
|
||||||
|
volatile uint16_t Z;
|
||||||
|
|
||||||
|
int main ( void )
|
||||||
|
{
|
||||||
|
//RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; //Broder!!! Hvorfor var ikke den linjen kode her! Var Brage btw som fjernet den. Ingenting skjer hvis selve clocken ikke er på!
|
||||||
|
initAccelo();
|
||||||
|
initLacheur();
|
||||||
|
while(1){
|
||||||
|
Melding = KattRecupAccelo();
|
||||||
|
LacheVoile(Melding);
|
||||||
|
//Juste pour essayer de regarder ce que ça affiche
|
||||||
|
X=Melding[0];
|
||||||
|
Y=Melding[1];
|
||||||
|
Z=Melding[2];
|
||||||
|
}
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) ;
|
||||||
|
Timer_Init(TIM1, ARR_VAL, PSC_VAL);
|
||||||
|
|
||||||
|
//Test du PWM
|
||||||
|
//PORTA & 0x00000400)>>10
|
||||||
|
MyTimer_PWM(TIM1, 3);
|
||||||
|
Set_DutyCycle_PWM(TIM1, 3, 10);
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
//DEL INTERNE
|
||||||
|
#if INTERNE
|
||||||
|
initGPIO_Interne();
|
||||||
|
MyTimer_ActiveIT(TIM3, 2, commuterDEL_Interne);
|
||||||
|
#else
|
||||||
|
//DEL EXTERNE BRANCHE SUR PB8 et GND (D14 & D8 AVEC LA TEXTE BLEUE SUR LA CARTE)
|
||||||
|
initGPIO_Externe();
|
||||||
|
MyTimer_ActiveIT(TIM2, 2, commuterDEL_Externe);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue