diff --git a/driver/uart.c b/driver/uart.c
index 42395d2..402d9a8 100644
--- a/driver/uart.c
+++ b/driver/uart.c
@@ -2,30 +2,11 @@
#include "gpio.h"
//faire GPIO
-char data1 = 0;
-char data2 = 0;
-char data3 = 0;
+void (* pFncUART) (uint16_t data); /* d�claration d�un pointeur de fonction */
-void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr){
- MyUART_setClockBit(UARTStructPtr); //Clock enable and setting the baud.
- UARTStructPtr->UART->CR1 = 0x00; // Clear ALL
- UARTStructPtr->UART->CR1 |= USART_CR1_UE;
- UARTStructPtr->UART->CR1 |= ((UARTStructPtr->length)<<12); //Setting the Length of the data transmitted
-
- UARTStructPtr->UART->CR1 &= ~(0x3<<9); //reset CR1 9-10 bits, Parity Selection
- if(UARTStructPtr->parity != parityNone) //if parity is enabled
- {
- UARTStructPtr->UART->CR1 |= (UARTStructPtr->parity<<9); //depending on the parity changing the 9th bit, and set 10th bit to 1
- }
-
- UARTStructPtr->UART->CR2 &= ~(0x3<<12); //reset CR2 13-12 bits, Stop bits
- if(UARTStructPtr->stop != stopBit1) //if stop bits > 1
- {
- UARTStructPtr->UART->CR2 |= (UARTStructPtr->stop<<12); //depending on the stop changing the 12th and 13th bit.
- }
- //TxD Enable, RxD Enable, USART Global Enable
- UARTStructPtr->UART->CR1 |= (USART_CR1_TE | USART_CR1_RE);
- MyUART_ActiveIT(UARTStructPtr->UART,1);
+void MyUART_Init_Periph (void (* ptrFonction)(uint16_t))
+{
+ pFncUART = ptrFonction; /* affectation du pointeur */
}
int MyUART_setClockBit(MyUART_Struct_Typedef * UARTStructPtr)
@@ -53,6 +34,25 @@ int MyUART_setClockBit(MyUART_Struct_Typedef * UARTStructPtr)
}
}
+uint8_t MyUART_GetInterruptNum(USART_TypeDef * UART)
+{
+ if(UART == USART1)
+ {
+ return USART1_IRQn;
+ }
+ else if(UART == USART2)
+ {
+ return USART2_IRQn;
+ }
+ else if(UART == USART3)
+ {
+ return USART3_IRQn;
+ }
+ else{
+ return 0;
+ }
+}
+
void MyUART_ActiveIT(USART_TypeDef * UART, uint8_t Prio)
{
uint32_t IRQNumber = MyUART_GetInterruptNum(UART);
@@ -61,6 +61,28 @@ void MyUART_ActiveIT(USART_TypeDef * UART, uint8_t Prio)
NVIC->ISER[1] |= (0x1<<(IRQNumber-32)); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[0])
}
+void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr){
+ MyUART_setClockBit(UARTStructPtr); //Clock enable and setting the baud.
+ UARTStructPtr->UART->CR1 = 0x00; // Clear ALL
+ UARTStructPtr->UART->CR1 |= USART_CR1_UE;
+ UARTStructPtr->UART->CR1 |= ((UARTStructPtr->length)<<12); //Setting the Length of the data transmitted
+
+ UARTStructPtr->UART->CR1 &= ~(0x3<<9); //reset CR1 9-10 bits, Parity Selection
+ if(UARTStructPtr->parity != parityNone) //if parity is enabled
+ {
+ UARTStructPtr->UART->CR1 |= (UARTStructPtr->parity<<9); //depending on the parity changing the 9th bit, and set 10th bit to 1
+ }
+
+ UARTStructPtr->UART->CR2 &= ~(0x3<<12); //reset CR2 13-12 bits, Stop bits
+ if(UARTStructPtr->stop != stopBit1) //if stop bits > 1
+ {
+ UARTStructPtr->UART->CR2 |= (UARTStructPtr->stop<<12); //depending on the stop changing the 12th and 13th bit.
+ }
+ //TxD Enable, RxD Enable, USART Global Enable
+ UARTStructPtr->UART->CR1 |= (USART_CR1_TE | USART_CR1_RE);
+ MyUART_ActiveIT(UARTStructPtr->UART,1);
+}
+
void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr)
{
MyGPIO_Struct_TypeDef rxd,txd;
@@ -87,8 +109,8 @@ void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr)
void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data)
{
UART->UART->DR = data;
- //du DR au Registre de Transmission, on attend que le bit de stop soit envoyé
- while (!(UART->UART->SR & USART_SR_TC));
+ //du DR au Registre de Transmission, on attend que le shift register ai récupéré le DR
+ while (!(UART->UART->SR & USART_SR_TXE));
}
uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART)
@@ -99,30 +121,12 @@ uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART)
return data;
}
-uint8_t MyUART_GetInterruptNum(USART_TypeDef * UART)
-{
- if(UART == USART1)
- {
- return USART1_IRQn;
- }
- else if(UART == USART2)
- {
- return USART2_IRQn;
- }
- else if(UART == USART3)
- {
- return USART3_IRQn;
- }
- else{
- return 0;
- }
-}
-
void USART1_IRQHandler(void)
{
if((USART1->SR & USART_SR_RXNE) == USART_SR_RXNE) //verify the flag
{
- data1 = USART1->DR; // read received data
+ if (pFncUART != 0)
+ (*pFncUART) (USART1->DR); /* appel indirect de la fonction */
USART1->SR &= ~USART_SR_RXNE; //flag to 0
}
}
@@ -131,7 +135,8 @@ void USART2_IRQHandler(void)
{
if((USART2->SR & USART_SR_RXNE) == USART_SR_RXNE) //verify the flag
{
- data2 = USART2->DR; // read received data
+ if (pFncUART != 0)
+ (*pFncUART) (USART2->DR); /* appel indirect de la fonction */
USART2->SR &= ~USART_SR_RXNE; //flag to 0
}
}
@@ -141,26 +146,12 @@ void USART3_IRQHandler(void)
// Check if receive data register not empty
if((USART3->SR & USART_SR_RXNE) == USART_SR_RXNE) //verify the flag
{
- data3 = USART3->DR; // read received data
- // do something with received data
+ if (pFncUART != 0)
+ (*pFncUART) (USART3->DR); /* appel indirect de la fonction */
USART2->SR &= ~USART_SR_RXNE; //flag to 0
}
}
-
-
-char MyUART_Read(MyUART_Struct_Typedef * UARTStructPtr)
-{
- if(UARTStructPtr->UART == USART1)
- return data1;
- else if(UARTStructPtr->UART == USART2)
- return data2;
- else if(UARTStructPtr->UART == USART3)
- return data3;
- else
- return 0xFF;
-}
-
/* exemple utilisation fonction :
UART1.UART = USART1; // choix UART (USART1, USART2, USART3)
diff --git a/driver/uart.h b/driver/uart.h
index a124025..e95c565 100644
--- a/driver/uart.h
+++ b/driver/uart.h
@@ -30,10 +30,7 @@ typedef struct {
void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr);
void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr);
-int MyUART_setClockBit(MyUART_Struct_Typedef * UARTStructPtr);
void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data);
uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART);
-void MyUART_ActiveIT(USART_TypeDef * UART, uint8_t Prio);
-uint8_t MyUART_GetInterruptNum(USART_TypeDef * UART);
-char MyUART_Read(MyUART_Struct_Typedef * UARTStructPtr);
+void MyUART_Init_Periph (void (* ptrFonction)(uint16_t));
#endif
diff --git a/implementation/remote.c b/implementation/remote.c
index 8b13789..aa1091e 100644
--- a/implementation/remote.c
+++ b/implementation/remote.c
@@ -1 +1,18 @@
+#include "remote.h"
+#include "../driver/gpio.h"
+
+MyUART_Struct_Typedef uartCool = {USART1,9600,lengthBit8,parityNone,stopBit1};
+
+void remote(uint16_t data)
+{
+ //MyGPIO_Set(GPIOA,5);
+ MyUART_Send(&uartCool,data);
+}
+
+void initRemote(void)
+{
+ MyUART_InitGPIO(&uartCool);
+ MyUART_Init(&uartCool);
+ MyUART_Init_Periph(remote);
+}
diff --git a/implementation/remote.h b/implementation/remote.h
index cfed997..ba61449 100644
--- a/implementation/remote.h
+++ b/implementation/remote.h
@@ -4,4 +4,7 @@
//XBEE 9600 baud, zero parite, 1 bit de stop,
+void remote(uint16_t data);
+void initRemote(void);
+
#endif
diff --git a/keilproject/Source/Principale.c b/keilproject/Source/Principale.c
index 35174fc..cc8f9ec 100644
--- a/keilproject/Source/Principale.c
+++ b/keilproject/Source/Principale.c
@@ -6,20 +6,11 @@
int main (void)
{
- //MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
- //MyGPIO_Init(&led); //test des leds pour ignorer les contraintes liées aux différents ports
+ MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
+ MyGPIO_Init(&led); //test des leds pour ignorer les contraintes liées aux différents ports
- MyUART_Struct_Typedef uartCool = {USART2,9600,lengthBit8,parityNone,stopBit1};
-
- MyUART_InitGPIO(&uartCool);
- MyUART_Init(&uartCool);
+ initRemote();
while(1){
- if(MyUART_Read(&uartCool) == 0x61)
- {
- MyGPIO_Set(GPIOA,5);
- MyUART_Send(&uartCool,'o');
- MyUART_Send(&uartCool,'k');
- }
};
}
diff --git a/keilproject/voilier.uvoptx b/keilproject/voilier.uvoptx
index 592bf50..e3c06e3 100644
--- a/keilproject/voilier.uvoptx
+++ b/keilproject/voilier.uvoptx
@@ -436,39 +436,7 @@
3
0
- 17
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- .\Source\Principale.c
-
-
-
-
- 4
- 0
- 19
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- .\Source\Principale.c
-
-
-
-
- 5
- 0
- 20
+ 14
1
0
0