UART init and send
This commit is contained in:
parent
c404ceeab2
commit
4b6629eb48
5 changed files with 93 additions and 36 deletions
11
Drivers/Include/Driver_UART.h
Normal file
11
Drivers/Include/Driver_UART.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef MYUART_H
|
||||||
|
#define MYUART_H
|
||||||
|
|
||||||
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
|
void UART_send(char data);
|
||||||
|
void UART_init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
21
Drivers/Sources/Driver_UART.c
Normal file
21
Drivers/Sources/Driver_UART.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "Driver_UART.h"
|
||||||
|
|
||||||
|
|
||||||
|
void UART_init()
|
||||||
|
{
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // Validation horloge USART1
|
||||||
|
USART1->CR1 |= USART_CR1_UE; // Activer l'USART
|
||||||
|
USART1->CR1 &= ~USART_CR1_M; // Choisir la taille 8bits de donnée
|
||||||
|
USART1->CR2 |= USART_CR2_STOP; // 1 seul bit de stop
|
||||||
|
USART1->BRR |= 468 << 4; // Fixe le baud rate à 9600bps
|
||||||
|
USART1->BRR |= 75; // Fixe le baud rate à 9600bps partie fractionnaire
|
||||||
|
//USART1->BRR = 72000000/9600; // Fixer le Baudrate à 9600
|
||||||
|
USART1->CR1 |= USART_CR1_TE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART_send(char data)
|
||||||
|
{
|
||||||
|
USART1->DR |= data;
|
||||||
|
while(!(USART1->SR & USART_SR_TC)){} //Attendre la fin de transmission
|
||||||
|
}
|
||||||
|
|
|
@ -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=-1,-1,-1,-1,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=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>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
|
@ -143,7 +143,40 @@
|
||||||
<Name>-U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
|
<Name>-U -O206 -S8 -C0 -P00 -N00("") -D00(00000000) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
</TargetDriverDllRegistry>
|
</TargetDriverDllRegistry>
|
||||||
<Breakpoint/>
|
<Breakpoint>
|
||||||
|
<Bp>
|
||||||
|
<Number>0</Number>
|
||||||
|
<Type>0</Type>
|
||||||
|
<LineNumber>47</LineNumber>
|
||||||
|
<EnabledFlag>1</EnabledFlag>
|
||||||
|
<Address>0</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>
|
||||||
|
<HtxType>0</HtxType>
|
||||||
|
<ManyObjects>0</ManyObjects>
|
||||||
|
<SizeOfObject>0</SizeOfObject>
|
||||||
|
<BreakByAccess>0</BreakByAccess>
|
||||||
|
<BreakIfRCount>1</BreakIfRCount>
|
||||||
|
<Filename>U:\INSA\Microcontrôleur\Projet_Voilier_grp\Voilier\GPIO_Test\Sources\Main.c</Filename>
|
||||||
|
<ExecCommand></ExecCommand>
|
||||||
|
<Expression>\\GPIO_Test\Sources/Main.c\47</Expression>
|
||||||
|
</Bp>
|
||||||
|
</Breakpoint>
|
||||||
<Tracepoint>
|
<Tracepoint>
|
||||||
<THDelay>0</THDelay>
|
<THDelay>0</THDelay>
|
||||||
</Tracepoint>
|
</Tracepoint>
|
||||||
|
@ -416,24 +449,12 @@
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>1</GroupNumber>
|
<GroupNumber>1</GroupNumber>
|
||||||
<FileNumber>3</FileNumber>
|
<FileNumber>3</FileNumber>
|
||||||
<FileType>5</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<bDave2>0</bDave2>
|
<bDave2>0</bDave2>
|
||||||
<PathWithFileName>..\Drivers\Include\Driver_GPIO.h</PathWithFileName>
|
<PathWithFileName>..\Drivers\Sources\Driver_UART.c</PathWithFileName>
|
||||||
<FilenameWithoutPath>Driver_GPIO.h</FilenameWithoutPath>
|
<FilenameWithoutPath>Driver_UART.c</FilenameWithoutPath>
|
||||||
<RteFlg>0</RteFlg>
|
|
||||||
<bShared>0</bShared>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<GroupNumber>1</GroupNumber>
|
|
||||||
<FileNumber>4</FileNumber>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<tvExp>0</tvExp>
|
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
|
||||||
<bDave2>0</bDave2>
|
|
||||||
<PathWithFileName>..\Drivers\Include\Driver_Timer.h</PathWithFileName>
|
|
||||||
<FilenameWithoutPath>Driver_Timer.h</FilenameWithoutPath>
|
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<bShared>0</bShared>
|
<bShared>0</bShared>
|
||||||
</File>
|
</File>
|
||||||
|
@ -447,7 +468,7 @@
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
<File>
|
<File>
|
||||||
<GroupNumber>2</GroupNumber>
|
<GroupNumber>2</GroupNumber>
|
||||||
<FileNumber>5</FileNumber>
|
<FileNumber>4</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
|
|
|
@ -394,14 +394,9 @@
|
||||||
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<FileName>Driver_GPIO.h</FileName>
|
<FileName>Driver_UART.c</FileName>
|
||||||
<FileType>5</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\Drivers\Include\Driver_GPIO.h</FilePath>
|
<FilePath>..\Drivers\Sources\Driver_UART.c</FilePath>
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>Driver_Timer.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
|
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
@ -811,14 +806,9 @@
|
||||||
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
||||||
</File>
|
</File>
|
||||||
<File>
|
<File>
|
||||||
<FileName>Driver_GPIO.h</FileName>
|
<FileName>Driver_UART.c</FileName>
|
||||||
<FileType>5</FileType>
|
<FileType>1</FileType>
|
||||||
<FilePath>..\Drivers\Include\Driver_GPIO.h</FilePath>
|
<FilePath>..\Drivers\Sources\Driver_UART.c</FilePath>
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>Driver_Timer.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
|
|
||||||
</File>
|
</File>
|
||||||
</Files>
|
</Files>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include "Driver_GPIO.h"
|
#include "Driver_GPIO.h"
|
||||||
#include "Driver_Timer.h"
|
#include "Driver_Timer.h"
|
||||||
|
#include "Driver_UART.h"
|
||||||
|
|
||||||
|
char data = 'A';
|
||||||
|
int cmp = 0;
|
||||||
|
|
||||||
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
|
||||||
|
@ -36,6 +40,16 @@ int main (void){
|
||||||
|
|
||||||
MyTimer_PWM(&TIM500ms, 50);
|
MyTimer_PWM(&TIM500ms, 50);
|
||||||
|
|
||||||
|
|
||||||
|
UART_init();
|
||||||
|
|
||||||
|
while (cmp < 26) {
|
||||||
|
UART_send(data+cmp);
|
||||||
|
cmp ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
// if (MyGPIO_Read(BP.GPIO,BP.GPIO_Pin)==0){
|
// if (MyGPIO_Read(BP.GPIO,BP.GPIO_Pin)==0){
|
||||||
// MyGPIO_Set(LED.GPIO,LED.GPIO_Pin);
|
// MyGPIO_Set(LED.GPIO,LED.GPIO_Pin);
|
||||||
|
|
Loading…
Reference in a new issue