Picproje Elektronik Sitesi

MİKRODENETLEYİCİLER => ARM => Konuyu başlatan: respected - 19 Temmuz 2013, 04:03:56

Başlık: STM32F4 USART ile gelen bilgi neden kayar?
Gönderen: respected - 19 Temmuz 2013, 04:03:56
STM32F4 ile usart konusunda string işlemleri konusunda testler yapıyorum.

USART1 de interrupt rutini aşağıdaki gibidir.  Gelen string lcd de yazdırıyorum. Sürekli kayarak geliyor.
1-Gönderdiğim cihazda \f    \n  gibi seçenekleri ekledim çıkardım nafile.
2- String uzunluğunu azalttım. 5 karakter gönderiyorum.  received_string  dizisinin boyutunu gönderdiğim string uzunluğunda yapıyorum.
3- Kodlar içerisinde math.h  kütüphanesini kaldırdım.
4- STM32F4 için Clock Configuration Tool ile sistem hızını ayarladım.
5- received_string dizisine gelen bilgiyi başka bir dizi içerisine kopyalayıp denedim.
  Belki daha da fazla şey yapmışımdır. Şimdilik aklıma gelenler bunlar. Yinede string kayarak geliyor.  Bu konuda tecrübesi olan arkadaş varmı?
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


if((t!='n')&&(cnt < MAX_STRLEN)){

received_string[cnt] = t;
cnt++;
}
else{ // otherwise reset the character counter and print the received string
cnt = 0;
// USART_puts(USART1, received_string);// Data gondermek istenirse acilacak

}
}
}


Usart conf kısmı.

void usart_kur(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);// USART clock enable yap1l1r.

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_100MHz; // 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);



// USART ayar
USART_InitStructure.USART_BaudRate = 9600; // 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_Rx | USART_Mode_Tx; // 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

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1 receive interrupt
 



/* Configure the NVIC Preemption Priority Bits */

/* Enable the USART1 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);
NVIC_EnableIRQ(USART1_IRQn);



}

Başlık: Ynt: STM32F4 USART ile gelen bilgi neden kayar?
Gönderen: Klein - 19 Temmuz 2013, 17:19:12
Kayarak gelmekten kasıtı tam olarak nedir? nereye doğru kayar? başına sonuna bir karakter mi akleniyor?

string sonu için 'n' karakterini beklemişsiniz. Stringin sonunda 'n' karakteri geliyor mu?
ayrıca 'n' herhangi bir metin içerisinde kullanılabilecek bir karakter. '\n'  yazmak isteyip yanlışlıkla 'n' yazmış olabilir misiniz?
Başlık: Ynt: STM32F4 USART ile gelen bilgi neden kayar?
Gönderen: respected - 20 Temmuz 2013, 01:27:16
Evet hocam kaymasından kasıt sağa sola 1,2,3 ya da 4 karakter düzensiz olarak hareket etmesidir. n  hatalı yazmışım \n olacak.
Sanki ilk gönderilen data ile sonrakiler farklı geliyormuş gibi davranıyor. Oysa hep aynı bilgiler gönderiyorum.
Başlık: Ynt: STM32F4 USART ile gelen bilgi neden kayar?
Gönderen: Klein - 20 Temmuz 2013, 12:00:27
 USART_puts(USART1, received_string);// Data gondermek istenirse acilacak

bu satırı açıp.  echo yaptırarak istenmeyen karakterler gelip gelmediğini kontrol eder misin?
belki LCD'ye yazarken bir şeyler yanlış gidiyordur.
Başlık: Ynt: STM32F4 USART ile gelen bilgi neden kayar?
Gönderen: respected - 21 Temmuz 2013, 00:20:54
Hocam il dışındayım. Yarın dener buraya yazarım
Başlık: Ynt: STM32F4 USART ile gelen bilgi neden kayar?
Gönderen: respected - 21 Temmuz 2013, 23:10:42
Hocam istenmeyen karakterler geliyor. Arada benim göndermediğim garip garip karakterler tekrarlıyor.