<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=46&amp;t=10416&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-01-28T10:49:05+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=46&amp;t=10416&amp;mode</id>
<entry>
<author><name><![CDATA[toch88]]></name></author>
<updated>2015-01-28T10:49:05+01:00</updated>
<published>2015-01-28T10:49:05+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10416&amp;p=116241#p116241</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10416&amp;p=116241#p116241"/>
<title type="html"><![CDATA[USART STM32F051R8T8]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10416&amp;p=116241#p116241"><![CDATA[
Witam <br /><br />Mam problem z odbieraniem wiecej niż jednego bajta w USART, korzystam z przerwań.<br />Petla główna wygląda tak:<br />[syntax=c]void HyperTerminal_Interrupt(void)<br />{<br />    <br />  /* NVIC configuration */<br />  NVIC_Config();<br />  <br />  /* USARTx configuration ------------------------------------------------------*/<br />  USARTInit();<br />  <br /><br />  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);<br /><br />  /* Infinite loop */<br />  while (1)<br />  {<br />  }<br />}[/syntax]<br /><br />konfiguracja przerwania:<br /><br />[syntax=c]void NVIC_Config(void)<br />{<br />  NVIC_InitTypeDef NVIC_InitStructure;<br /><br />  /* Enable the USART2 Interrupt */<br />  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;<br />  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;<br />  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;<br />  NVIC_Init(&amp;NVIC_InitStructure);<br />}[/syntax]<br /><br />konfiguracja USARTA<br /><br />[syntax=c]void USARTInit(void)<br />{<br />    GPIO_InitTypeDef GPIO_InitStructure;<br />    USART_InitTypeDef USART_InitStructure;<br />    <br />RCC-&gt;AHBENR|= (1&lt;&lt;19); // Włącz zegar<br /><br />//Włącz PORT Pin 8 digtal<br />GPIOC-&gt;MODER|=(1&lt;&lt;18);<br /><br /><br />    USART_InitStructure.USART_BaudRate = 9600;<br />    USART_InitStructure.USART_WordLength = USART_WordLength_8b;<br />    USART_InitStructure.USART_StopBits = USART_StopBits_1;<br />    USART_InitStructure.USART_Parity = USART_Parity_No;<br />    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;<br />    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;<br /><br />    /* Enable GPIO clock */<br />    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);<br /><br />    /* Enable USART clock */<br />    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);<br />    <br />    /* Connect PXx to USARTx_Tx */<br />    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);<br /><br />    /* Connect PXx to USARTx_Rx */<br />    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);<br />    <br />    /* Configure USART Tx, Rx as alternate function push-pull */<br />    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;<br />    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;<br />    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br />    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;<br />    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;<br />    GPIO_Init(GPIOA, &amp;GPIO_InitStructure);<br /><br />    /* USART configuration */<br />    USART_Init(USART1, &amp;USART_InitStructure);<br /><br />    /* Enable USART */<br />    USART_Cmd(USART1, ENABLE);<br /><br />}[/syntax]<br /><br />przerwanie :<br /><br />[syntax=c]void USART1_IRQHandler(void)<br />{<br />  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)<br />  {<br />    /* Read one byte from the receive data register */<br />    /*1*/RxBuffer&#91;RxCount&#93; = (USART_ReceiveData(USART1));<br />    if(RxBuffer&#91;RxCount&#93;==49)<br />    {<br />    /*2*/GPIOC-&gt;ODR |= (1&lt;&lt;9);<br /><br />    }<br />    else{<br />    GPIOC-&gt;ODR &amp;= (0&lt;&lt;9);<br />   }<br />    RxCount++;<br /><br />    if(RxCount &gt; NbrOfDataToRead)<br />    {<br />      /* Disable the USART1 Receive interrupt */<br /><br />      RxCount=0;<br />      //USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);<br />    }<br />  }[/syntax]<br /><br />w terminalu wpisuje<br />[syntax=bash]12(bez znaku konczenia 0x0D)[/syntax]<br /><br />W tym momencie w debuggerze widzę że wchodzi mi do przerwania, odczytuje pierwszą cyfre /*1*/, zapala diode /*2*/, natomiast  po przejściu tej pętli, i wejściu do przerwania jeszcze raz   if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) pokazuje RESET.<br />We wnętrzu funkcji problem występuje w lini bitpos &amp;= USARTx-&gt;ISR; w tym momencie jest tak że <br />&quot;USARTx-&gt;ISR&quot;0b11000000000000011011000<br />&quot;bitpos&quot;0b100000<br /><br />w Reference manual <a href="https://www.google.pl/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0CCIQFjAA&amp;url=http%3A%2F%2Fwww.st.com%2Fweb%2Fen%2Fresource%2Ftechnical%2Fdocument%2Freference_manual%2FDM00031936.pdf&amp;ei=h6_IVPyVOdXzauvcgdgP&amp;usg=AFQjCNF9ugmbHfuVEZ4HCkzIzQnK7lfdhg&amp;sig2=Teiux6Zq3cUDElDfYzYh2A"  class="postlink">https://www.google.pl/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0CCIQFjAA&amp;url=http%3A%2F%2Fwww.st.com%2Fweb%2Fen%2Fresource%2Ftechnical%2Fdocument%2Freference_manual%2FDM00031936.pdf&amp;ei=h6_IVPyVOdXzauvcgdgP&amp;usg=AFQjCNF9ugmbHfuVEZ4HCkzIzQnK7lfdhg&amp;sig2=Teiux6Zq3cUDElDfYzYh2A</a><br />na stronie 732 jest napisane wyraźnie że:<br /><br />Bit 6 TC: Transmission complete<br />0: Transmission is not complete<br />1: Transmission is complete<br /><br />tylko dlaczego ma mieć to na wpływ odbieranie skoro to się tyczy transmisji?<br /><br />[syntax=c]bitpos = USART_IT &gt;&gt; 0x10;<br />  bitpos = (uint32_t)0x01 &lt;&lt; bitpos;<br />  bitpos &amp;= USARTx-&gt;ISR;<br />  if ((itmask != (uint16_t)RESET)&amp;&amp;(bitpos != (uint16_t)RESET))<br />  {<br />    bitstatus = SET;<br />  }<br />  else<br />  {<br />    bitstatus = RESET;<br />  }[/syntax]<br /><br />nie powinno być tak?<br /><br />[syntax=c]bitpos = USART_IT &gt;&gt; 0x10;<br />  bitpos = (uint32_t)0x01 &lt;&lt; bitpos;<br />  bitpos &amp;= USARTx-&gt;ISR;<br />  if ((itmask != (uint16_t)RESET)||(bitpos != (uint16_t)RESET))<br />  {<br />    bitstatus = SET;<br />  }<br />  else<br />  {<br />    bitstatus = RESET;<br />  }[/syntax]<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 18 minutach ]</span></strong><br /><br />Aaaaa przepraszam zamuliłem, ustawiłem tak breakpointa ze mi się zawieszał w przerwaniu ;/ <br />Debugowanie Uarta eh...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1138">toch88</a> — 28 sty 2015, o 10:49</p><hr />
]]></content>
</entry>
</feed>