UART interrupt added
This commit is contained in:
parent
4b6629eb48
commit
e8800d0c58
4 changed files with 40 additions and 35 deletions
|
@ -4,7 +4,9 @@
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
void UART_send(char data);
|
void UART_send(char data);
|
||||||
void UART_init();
|
void UART_init(void);
|
||||||
|
void UART_ITHandler(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
#include "Driver_UART.h"
|
#include "Driver_UART.h"
|
||||||
|
|
||||||
|
|
||||||
void UART_init()
|
void UART_init(void)
|
||||||
{
|
{
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1
|
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1
|
||||||
USART1->CR1 |= USART_CR1_UE; // Activer l'USART
|
USART1->CR1 |= USART_CR1_UE; // Activer l'USART
|
||||||
USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée
|
USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée
|
||||||
USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop
|
USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop
|
||||||
USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps
|
USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps partie entière
|
||||||
USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire
|
USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire
|
||||||
//USART1->BRR = 72000000/9600; // Fixer le Baudrate à 9600
|
//USART1->BRR = 72000000/9600; // Fixer le Baudrate à 9600
|
||||||
USART1->CR1 |= USART_CR1_TE;
|
USART1->CR1 |= USART_CR1_TE; // Autoriser la transmission
|
||||||
|
USART1->CR1 |= USART_CR1_RE; // Activer la réception
|
||||||
|
USART1->CR1 |= USART_CR1_TCIE; // Activer l'interruption de transmission
|
||||||
|
USART1->CR1 |= USART_CR1_RXNEIE; // Activer l'interruption de réception
|
||||||
}
|
}
|
||||||
|
|
||||||
void UART_send(char data)
|
void UART_send(char data)
|
||||||
|
@ -19,3 +22,16 @@ void UART_send(char data)
|
||||||
while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission
|
while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UART_ITHandler(void)
|
||||||
|
{
|
||||||
|
if (USART1->SR & USART_SR_RXNE) // si une donnée a été reçue
|
||||||
|
{
|
||||||
|
char received_data = USART1->DR; // lire la donnée reçue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (USART1->SR & USART_SR_TC) // si la transmission est terminée
|
||||||
|
{
|
||||||
|
USART1->SR &= ~USART_SR_TC; // effacer le bit de transmission terminée
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>DLGDARM</Key>
|
<Key>DLGDARM</Key>
|
||||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=949,269,1397,683,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=911,135,1505,886,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=930,345,1378,759,1)(161=1383,268,1831,682,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
|
@ -147,25 +147,9 @@
|
||||||
<Bp>
|
<Bp>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Type>0</Type>
|
<Type>0</Type>
|
||||||
<LineNumber>47</LineNumber>
|
<LineNumber>51</LineNumber>
|
||||||
<EnabledFlag>1</EnabledFlag>
|
<EnabledFlag>1</EnabledFlag>
|
||||||
<Address>0</Address>
|
<Address>134219346</Address>
|
||||||
<ByteObject>0</ByteObject>
|
|
||||||
<HtxType>0</HtxType>
|
|
||||||
<ManyObjects>0</ManyObjects>
|
|
||||||
<SizeOfObject>0</SizeOfObject>
|
|
||||||
<BreakByAccess>0</BreakByAccess>
|
|
||||||
<BreakIfRCount>0</BreakIfRCount>
|
|
||||||
<Filename>.\Sources\Main.c</Filename>
|
|
||||||
<ExecCommand></ExecCommand>
|
|
||||||
<Expression></Expression>
|
|
||||||
</Bp>
|
|
||||||
<Bp>
|
|
||||||
<Number>1</Number>
|
|
||||||
<Type>0</Type>
|
|
||||||
<LineNumber>47</LineNumber>
|
|
||||||
<EnabledFlag>1</EnabledFlag>
|
|
||||||
<Address>134219276</Address>
|
|
||||||
<ByteObject>0</ByteObject>
|
<ByteObject>0</ByteObject>
|
||||||
<HtxType>0</HtxType>
|
<HtxType>0</HtxType>
|
||||||
<ManyObjects>0</ManyObjects>
|
<ManyObjects>0</ManyObjects>
|
||||||
|
@ -174,7 +158,7 @@
|
||||||
<BreakIfRCount>1</BreakIfRCount>
|
<BreakIfRCount>1</BreakIfRCount>
|
||||||
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c</Filename>
|
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c</Filename>
|
||||||
<ExecCommand></ExecCommand>
|
<ExecCommand></ExecCommand>
|
||||||
<Expression>\\GPIO_Test\Sources/Main.c\47</Expression>
|
<Expression>\\GPIO_Test\Sources/Main.c\51</Expression>
|
||||||
</Bp>
|
</Bp>
|
||||||
</Breakpoint>
|
</Breakpoint>
|
||||||
<Tracepoint>
|
<Tracepoint>
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
#include "Driver_Timer.h"
|
#include "Driver_Timer.h"
|
||||||
#include "Driver_UART.h"
|
#include "Driver_UART.h"
|
||||||
|
|
||||||
char data = 'A';
|
char data[] = "Hello World";
|
||||||
int cmp = 0;
|
int i = 0;
|
||||||
|
int len = sizeof(data) - 1; // -1 pour ne pas envoyer le caractère nul
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
//Déclaration d'une LED et d'un BP par structure GPIO
|
//Déclaration d'une LED et d'un BP par structure GPIO
|
||||||
|
@ -43,9 +44,11 @@ int main (void){
|
||||||
|
|
||||||
UART_init();
|
UART_init();
|
||||||
|
|
||||||
while (cmp < 26) {
|
//NVIC_EnableIRQ(USART1_IRQn);// Activer les interruptions
|
||||||
UART_send(data+cmp);
|
|
||||||
cmp ++;
|
// Envoyer les données
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
UART_send(data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue