Skocz do zawartości

[C] [STM32F4] [STM32f429I-DISCO] Problem z transmisją USART


dominico12

Pomocna odpowiedź

Witam

Mam problem z transmisją USART w STM32F4 ,konwerter oparty na kostce FT232R ,tranzmisja woogóle nie występuje ,konwerter podłączony do portu PB6(RX konwertera) i PB7(TX konwertera) , używam USARTU1 ,na innych też nie działa ,nie mogę znaleść błędu w kodzie

#include "stm32f4xx.h"
#include "stm32f429i_discovery.h"

uint32_t timer_ms;

void SysTick_Handler()
{
if(timer_ms)
{
	timer_ms--;
}
}

void delay_ms(int ms)
{
timer_ms = ms;
while(timer_ms);
}



void send_char(volatile char *c);

int main(void)
{


RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOG ,ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB2Periph_USART1  ,ENABLE);

SysTick_Config(SystemCoreClock / 1000);

GPIO_InitTypeDef gpio;

GPIO_StructInit( &gpio );

gpio.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_UP;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOB , &gpio);

gpio.GPIO_Pin = GPIO_Pin_13;
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOG ,&gpio);

GPIO_SetBits(GPIOG ,GPIO_Pin_13);
delay_ms(200);
GPIO_ResetBits(GPIOG ,GPIO_Pin_13);
/*
gpio.GPIO_Pin = GPIO_Pin_7;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOB ,&gpio);
*/

GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); //connected PD5 to USART1_TX
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); //connected PD5 to USART1_RX

USART_InitTypeDef usart1;

USART_StructInit( &usart1 );

usart1.USART_BaudRate = 19200;
usart1.USART_WordLength = USART_WordLength_8b;
usart1.USART_StopBits = USART_StopBits_1;
usart1.USART_Parity = USART_Parity_No;
usart1.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usart1.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART1 ,&usart1);

USART_Cmd(USART1 ,ENABLE);

delay_ms(200);
GPIO_SetBits(GPIOG ,GPIO_Pin_13);
delay_ms(200);
send_char("a");
delay_ms(200);
GPIO_ResetBits(GPIOG ,GPIO_Pin_13);
while(1)
{
	//send_char("a");

}


return 0;
}


void send_char(volatile char *c)
{
	//while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
	while (!(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET));
	//while ((USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET));
	USART_SendData(USART1, (int)c);
}

Link do komentarza
Share on other sites

GPIO_InitTypeDef gpio;

GPIO_StructInit( &gpio );

gpio.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_UP;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOB , &gpio);

Ustawiasz obydwa piny jako wyjścia i na dodatek włączasz Pull-Up.

   GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); //connected PD5 to USART1_TX
   GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); //connected PD5 to USART1_RX 

Złe komentarze i to chyba wogóle nie jest potrzebne, ponieważ wcześniej masz:

gpio.GPIO_Mode = GPIO_Mode_AF;
Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.