Picproje Elektronik Sitesi

MİKRODENETLEYİCİLER => ARM => Konuyu başlatan: kimlenbu - 30 Nisan 2014, 09:44:55

Başlık: STM32F4 USART Problemi
Gönderen: kimlenbu - 30 Nisan 2014, 09:44:55
Selamlar,

Sorum basit ama ayrıntılı anlattım, lütfen yardım edin ağlayacağım artık...

STM32F4 Discovery'nin USART1'ini kullanarak PC ile haberleşmeye çalışıyorum. Ne veriler hyperterminal'e doğru gidiyor ne de doğru bir şekilde veri alabiliyorum.

115200bps, 8data, 1stop, parity yok, hardware flow kontrol yok. PC'den gönderdiğim verilere karşılık okuduğum değerlerin bazıları şunlar :

a -> O
b -> '
c -> N
e -> M
f -> &
g -> L

PC'de problem vardır diye başka makinada denedim sonuçlar aynı. STM32F4 168MHz'de değil de dahili osilatörle çalışıyordur belki dedim, system_st32f4xx.c dosyasında HSE frekansında sıkıntı varsa diye 407. satırdaki şu bölüme sonsuz döngü koydum, program burayı geçip çalıştı :
.....
  else
  { /* If HSE fails to start-up, the application will have wrong clock
         configuration. User can add here some code to deal with this error */
while(1){}

  }
.....


sadece tx ve rx uçlarını bağlamıştım, nolur nolmaz ground'u da bağladım değişen yok.

osiloskop, logic analyzer vs yok ne yazık ki donanımsal olarak bakamıyorum frekansa...

usart1 init kodlarım :

void USART1_Conf(void)
{
  GPIO_InitTypeDef GPIO_InitStructure; // this is for the GPIO pins used as TX and RX
USART_InitTypeDef USART_InitStructure;  // this is for the USART1 initilization
NVIC_InitTypeDef NVIC_InitStructure; // this is used to configure the NVIC (nested vector interrupt controller)

/* enable APB2 peripheral clock for USART1
* note that only USART1 and USART6 are connected to APB2
* the other USARTs are connected to APB1
*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/* enable the peripheral clock for the pins used by
* USART1, PB6 for TX and PB7 for RX
*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

/* This sequence sets up the TX and RX pins
* so they work correctly with the USART1 peripheral
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; // Pins 6 (TX) and 7 (RX) are used
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // the pins are configured as alternate function so the USART peripheral has access to them
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // this defines the IO speed and has nothing to do with the baudrate!
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // this defines the output type as push pull mode (as opposed to open drain)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // this activates the pullup resistors on the IO pins
GPIO_Init(GPIOB, &GPIO_InitStructure); // now all the values are passed to the GPIO_Init() function which sets the GPIO registers

/* The RX and TX pins are now connected to their AF
* so that the USART1 can take over control of the
* pins
*/
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); //
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);

/* Now the USART_InitStruct is used to define the
* properties of USART1
*/
USART_InitStructure.USART_BaudRate = 115200; // the baudrate is set to the value we passed into this init function
USART_InitStructure.USART_WordLength = USART_WordLength_8b;// we want the data frame size to be 8 bits (standard)
USART_InitStructure.USART_StopBits = USART_StopBits_1; // we want 1 stop bit (standard)
USART_InitStructure.USART_Parity = USART_Parity_No; // we don't want a parity bit (standard)
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // we don't want flow control (standard)
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; // we want to enable the transmitter and the receiver
USART_Init(USART1, &USART_InitStructure); // again all the properties are passed to the USART_Init function which takes care of all the bit setting

/* Here the USART1 receive interrupt is enabled
* and the interrupt controller is configured
* to jump to the USART1_IRQHandler() function
* if the USART1 receive interrupt occurs
*/
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1 receive interrupt

NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; // we want to configure the USART1 interrupts
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;// this sets the priority group of the USART1 interrupts
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // this sets the subpriority inside the group
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // the USART1 interrupts are globally enabled
NVIC_Init(&NVIC_InitStructure); // the properties are passed to the NVIC_Init function which takes care of the low level stuff

// finally this enables the complete USART1 peripheral
USART_Cmd(USART1, ENABLE);
}


12 karakter dolduğunda okuma yapan kesme bloğum :

void USART1_IRQHandler(void){

// check if the USART1 receive interrupt flag was set
if( USART_GetITStatus(USART1, USART_IT_RXNE) ){

static uint8_t cnt = 0; // this counter is used to determine the string length
char t = USART1->DR; // the character from the USART1 data register is saved in t

/* check if the received character is not the LF character (used to determine end of string)
* or the if the maximum string length has been been reached
*/
if( (t != 'n') && (cnt < MAX_STRLEN) ){
received_string[cnt] = t;
cnt++;
}
else{ // otherwise reset the character counter and print the received string
cnt = 0;
SSD1963_LCD_ShowString(395,378,received_string,BEYAZ,BILGIRENGI,&Font16x24);
// USART_puts(USART1, received_string);
}
}
}


karakter gönderen kod bloğu :

void USART_puts(USART_TypeDef* USARTx, volatile char *s){

while(*s){
// wait until data register is empty
while( !(USARTx->SR & 0x00000040) );
USART_SendData(USARTx, *s);
*s++;
}
}


hatayı bulamıyorum bir türlü, sıkıntı ne olabilir ?
Başlık: Ynt: STM32F4 USART Problemi
Gönderen: respected - 30 Nisan 2014, 09:51:29
max232 benzeri bir entegre kullandın mı?  Discovery den  pc ye bağlantıyı nasıl yaptın ? Bu kısmı anlatırsan sorunu çözebiliriz.
Başlık: Ynt: STM32F4 USART Problemi
Gönderen: camby - 30 Nisan 2014, 09:54:37
Kodlara bakmadan ilk diyeceğim :

1- arada ne var ?

2- hyper terminal'den kurtulun , hemen docklight indirin.
Başlık: Ynt: STM32F4 USART Problemi
Gönderen: kimlenbu - 30 Nisan 2014, 10:35:45
Bağlantım şu şekilde PC->usb to serial kablo->Discovery usart1 (tx,rx ve gnd uçları bağlı)

arada usb'den rs232'ye çevirici kablo vardı (prolific). Şimdi yeni dönüştürücü almaya çıkıyorum, siz söyleyince hatırladım, kullandığım kablo GSM/GPS modülüyle birlikte gelmişti ve benzer sıkıntılar çıkarmıştı zamanında.

hyperterminal'i de denedim ama realterm kullanıyorum aslında, anlaşılır olsun diye hyperterminal yazdım.

Docklight indirdim 1 saate kadar denemiş olurum.
Başlık: Ynt: STM32F4 USART Problemi
Gönderen: respected - 30 Nisan 2014, 10:43:47
Bence araya TTL converter devresi ekle sorun çözülür.
Başlık: Ynt: STM32F4 USART Problemi
Gönderen: kimlenbu - 30 Nisan 2014, 13:59:56
Kabloda sıkıntı var diye gittim Digitus marka çevirici aldım düzelmedi, nolur nolmaz diye MAX3232 de almıştım, dediğiniz gibi araya ttl converter koyunca kodda hiçbir değişiklik yapmadan düzeldi, çok teşekkür ederim.

yalnız karman çorman oldu ortalık, ne nereye giriyor belli değil...

(http://i60.tinypic.com/2ikwpy1.jpg)
Başlık: Ynt: STM32F4 USART Problemi
Gönderen: enis - 01 Ekim 2014, 11:25:31
Merhaba aynı bord ile bende ugraşıyorum karşılaştığınız sorunla bende karşılaştım max232  ile denedim olmadı. resimdede pek anlayamadım yaptığınız bağlantıyı biraz daha açıklayabilirmisiniz yada resmini çekip koyabilirmisiniz?