UART+ADC+PWM+GPIO+INT
This commit is contained in:
commit
6687cffd8f
6 changed files with 112 additions and 33 deletions
21
Drivers/Include/Driver_ADC.h
Normal file
21
Drivers/Include/Driver_ADC.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef MYADC_H
|
||||
#define MYADC_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "Driver_GPIO.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ADC_TypeDef * ADC;
|
||||
char Channel;
|
||||
} MyADC_Struct_TypeDef;
|
||||
|
||||
|
||||
void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC);
|
||||
void MyADC_Base_Start(ADC_TypeDef * ADC);
|
||||
void MyADC_Base_Stop(ADC_TypeDef * ADC);
|
||||
void MyADC_Base_Interuption(ADC_TypeDef * ADC);
|
||||
int MyADC_Base_Result (MyADC_Struct_TypeDef * ADC);
|
||||
void MyADC_Init_Periph (void (*fct)(void));
|
||||
|
||||
#endif
|
|
@ -23,4 +23,5 @@ int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; // renvoie 0 ou autre
|
|||
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
||||
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
||||
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,35 +2,47 @@
|
|||
|
||||
|
||||
//---------------------FONCTION D'INITIALISATION-----------------//
|
||||
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr){
|
||||
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
|
||||
{
|
||||
|
||||
//INITIALISATION DE LA CLOCK CORRESPONDANT AU GPIO A, B ou C
|
||||
if (GPIOStructPtr->GPIO == GPIOA) {
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
|
||||
} else if (GPIOStructPtr->GPIO == GPIOB) {
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
|
||||
} else if (GPIOStructPtr->GPIO == GPIOC) {
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
|
||||
} else if (GPIOStructPtr->GPIO == GPIOD) {
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN;
|
||||
/* Activation of the GPIO port specific clock */
|
||||
if (GPIOStructPtr->GPIO == GPIOA)
|
||||
{
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
|
||||
}
|
||||
else if (GPIOStructPtr->GPIO == GPIOB)
|
||||
{
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
|
||||
}
|
||||
else if (GPIOStructPtr->GPIO == GPIOC)
|
||||
{
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
|
||||
}
|
||||
else if (GPIOStructPtr->GPIO == GPIOD)
|
||||
{
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN;
|
||||
}
|
||||
|
||||
|
||||
/* Reset, and then configuration writing of the selected GPIO Pin */
|
||||
if(GPIOStructPtr->GPIO_Pin <= 8)
|
||||
{
|
||||
GPIOStructPtr->GPIO->CRL &= ~0xF<<(4*(GPIOStructPtr->GPIO_Pin));
|
||||
GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf)<<(4*(GPIOStructPtr->GPIO_Pin));
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOStructPtr->GPIO->CRH &= ~0xF<<(4*((GPIOStructPtr->GPIO_Pin)%8));
|
||||
GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf)<<(4*((GPIOStructPtr->GPIO_Pin)%8));
|
||||
}
|
||||
|
||||
//CONFIGURATION DE LA PIN UTILISEE (voir table20 p9.1)
|
||||
if(GPIOStructPtr->GPIO_Pin < 8){
|
||||
GPIOStructPtr->GPIO->CRL &= ~(0xF << (4 * GPIOStructPtr->GPIO_Pin));
|
||||
GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf << (4 * GPIOStructPtr->GPIO_Pin));
|
||||
if(GPIOStructPtr->GPIO_Conf == (char)In_PullDown)
|
||||
{
|
||||
GPIOStructPtr->GPIO->ODR &= ~(0x1<<(GPIOStructPtr->GPIO_Pin));
|
||||
}
|
||||
else {
|
||||
GPIOStructPtr->GPIO->CRH &= ~(0xF << (4 * GPIOStructPtr->GPIO_Pin - 8));
|
||||
GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf << (4 * GPIOStructPtr->GPIO_Pin - 8));
|
||||
}
|
||||
|
||||
//CONFIGURATION DE L'ODR EN ENTREE (pull up et down uniquement)
|
||||
if(GPIOStructPtr->GPIO_Conf == In_PullUp){
|
||||
GPIOStructPtr->GPIO->ODR = 0x1;
|
||||
}
|
||||
else if(GPIOStructPtr->GPIO_Conf == In_PullDown){
|
||||
GPIOStructPtr->GPIO->ODR = 0x0;
|
||||
else if(GPIOStructPtr->GPIO_Conf == (char)In_PullUp)
|
||||
{
|
||||
GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,3 +74,4 @@ void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|||
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
||||
GPIO->ODR ^= (1 << GPIO_Pin);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,5 +42,5 @@ void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle){
|
|||
|
||||
Timer->Timer->CCER |= TIM_CCER_CC1E; // Canal CH1 validé par bit CC1E (registre CCER)
|
||||
Timer->Timer->CR1 |= TIM_CR1_CEN; // Lancement du timer
|
||||
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20%
|
||||
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20%
|
||||
}
|
||||
|
|
|
@ -446,7 +446,11 @@
|
|||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<<<<<<< HEAD
|
||||
<tvExp>0</tvExp>
|
||||
=======
|
||||
<tvExp>1</tvExp>
|
||||
>>>>>>> feature-branch
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>C:\Users\chanfreau\Downloads\voilier\Drivers\Sources\Driver_ADC.c</PathWithFileName>
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
#include "Driver_GPIO.h"
|
||||
#include "Driver_Timer.h"
|
||||
#include "Driver_UART.h"
|
||||
#include "Driver_ADC.h"
|
||||
|
||||
|
||||
char data[] = "Hello World";
|
||||
int i = 0;
|
||||
int len = sizeof(data) - 1; // -1 pour ne pas envoyer le caractère nul
|
||||
void ADC_interrup(void);
|
||||
|
||||
int main (void){
|
||||
//Déclaration d'une LED et d'un BP par structure GPIO
|
||||
MyGPIO_Struct_TypeDef LED;
|
||||
MyGPIO_Struct_TypeDef BP;
|
||||
MyUART_Struct_Typedef UART;
|
||||
//Déclaration d'un Timer 500 ms
|
||||
MyTimer_Struct_TypeDef TIM500ms;
|
||||
|
||||
//Déclaration ADC de Test
|
||||
MyADC_Struct_TypeDef ADCTEST;
|
||||
//Config LED PA5
|
||||
LED.GPIO_Conf = Out_Ppull;
|
||||
LED.GPIO_Pin = 5;
|
||||
|
@ -25,6 +37,9 @@ int main (void){
|
|||
TIM500ms.ARR = 5000;
|
||||
MyTimer_Base_Init(&TIM500ms);
|
||||
|
||||
//InitUART
|
||||
UART.UART = USART1;
|
||||
|
||||
/*
|
||||
TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH
|
||||
//TIM2->DIER |= TIM_DIER_UIE ;
|
||||
|
@ -36,13 +51,28 @@ int main (void){
|
|||
|
||||
MyTimer_PWM(&TIM500ms, 50);
|
||||
|
||||
while(1){
|
||||
// if (MyGPIO_Read(BP.GPIO,BP.GPIO_Pin)==0){
|
||||
// MyGPIO_Set(LED.GPIO,LED.GPIO_Pin);
|
||||
// }else{
|
||||
// MyGPIO_Reset(LED.GPIO,LED.GPIO_Pin);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions
|
||||
UART_InitGPIO(&UART);
|
||||
// Envoyer les données
|
||||
for (i = 0; i < len; i++) {
|
||||
UART_send(data[i]);
|
||||
}
|
||||
|
||||
//UART_read(data[i], &UART);
|
||||
|
||||
//ADC
|
||||
//TEST ADC//
|
||||
ADCTEST.ADC = ADC1;
|
||||
ADCTEST.Channel = 0;
|
||||
MyADC_Base_Init(&ADCTEST);
|
||||
MyADC_Base_Interuption(ADCTEST.ADC);
|
||||
MyADC_Init_Periph(ADC_interrup);
|
||||
|
||||
while(1){
|
||||
MyADC_Base_Start(ADCTEST.ADC);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,4 +82,14 @@ void TIM2_IRQHandler (void)
|
|||
MyGPIO_Toggle(GPIOA,5);
|
||||
TIM2->SR &= ~(1<<0);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
void Timer_interup(void)
|
||||
{
|
||||
MyGPIO_Toggle(GPIOA,5);
|
||||
}
|
||||
|
||||
//Interruption du programme par trigger de l'ADC
|
||||
void ADC_interrup()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue