<div dir="ltr">Dobry den,<div>omlouvam se, spise jen obecne tipy ale mam tu take jeden projekt s timto procesorem a prvni prijaty byte je ok.</div><div>mazete pri inicializaci priznaky chyb? nemate zapnutou autodetekci rychlosti? neprijimate znak drive nez se stabilizuji hodiny procesoru? nenabehne procesor rychleji nez to co je povesene na pinu UARTU a neprijme tak chybny znak?</div><div>S pozdravem TM.<br></div><div><br></div><div>P.S. Muj inicializacni kod vypada nasledovne, ale pouzivame zrejme jine knihovny + je to dost silene makro takze vam to asi prilis nepomuze:</div><div><div>#define uartini(name) \<br></div><div> UARTConfigure( name ## _UART, UART_ENABLE_PINS_TX_RX_ONLY); \</div><div> UARTSetLineControl( name ## _UART, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); \</div><div> UARTSetDataRate( name ## _UART, pc, name ## _BAUD); \</div><div> UARTEnable( name ## _UART, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));</div></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-08 20:40 GMT+02:00 <span dir="ltr"><<a href="mailto:nevrklap@volny.cz" target="_blank">nevrklap@volny.cz</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Zdravim,<br>
mame tu dva male projekty zalozene na procesoru PIC32MX795F512L.. (Microchip si vybral kolega programator, prosim nekomentovat :-)<br>
V obou pripadech se projevuje stejny problem - prvni byte (po zapnuti zarizeni) prijaty pres UART (odeslany typicky z PC) se neprijme korektne... vyvola se korektne preruseni, ale precte se nesmysl. Dalsi znaky uz chodi v poradku (vsechno typicky jednobytove prikazy..).<br>
Je to ponekud otravne, nesetkal se s tim prosim nekdo? Tento odkaz jsem kolegovi daval <a href="http://www.microchip.com/forums/m531951.aspx" rel="noreferrer" target="_blank">http://www.microchip.com/forums/m531951.aspx</a> ale zatim to nepomohlo...<br>
Nize je vyseknuty kod, ktery zmineny UART pouziva, pokud by mel nekdo chut se na to mrknout...<br>
Diky moc<br>
P.<br>
<br>
<br>
<br>
<br>
<br>
#include <plib.h><br>
#include <stdlib.h><br>
<br>
#define UART_HS_9600_ID (3) // Identifikator<br>
#define UART_HS_9600_BRG (1041) // BRG value<br>
#define UART_HS_9600_BRGH (1) // BRGH (high speed)<br>
<br>
#define UART_HS_115200_ID (9) // Identifikator<br>
#define UART_HS_115200_BRG (86) // BRG value<br>
#define UART_HS_115200_BRGH (1) // BRGH (high speed)<br>
<br>
#define UART_B_COMPILER UART2<br>
<br>
<br>
/**<br>
* Init UART module<br>
*/<br>
void UartInit(void){<br>
PORTSetPinsDigitalIn(IOPORT_UART_RX, BIT_UART_RX); // INPUT<br>
PORTReadBits(IOPORT_UART_RX, BIT_UART_RX);<br>
PORTSetPinsDigitalOut(IOPORT_UART_TX, BIT_UART_TX); // OUTPUT<br>
PORTSetBits(IOPORT_UART_TX, BIT_UART_TX);<br>
<br>
<br>
U2MODE = 0x8000; // Enable UART for 8-bit data, No parity, 1 stop<br>
U2MODESET = 0x80; // Enable UART wake-up from sleep<br>
<br>
// Nastavim Baud Rate pro High Speed rezim:<br>
UART_Sens_B_SetBrg(psUART_Sens_B->psCfg->ucBaudRateID, SYS_CLK_HS);<br>
<br>
<br>
// Parity, stopbit:<br>
U2MODECLR = 0b110; // b2-1 = 8-bit data, no parity<br>
U2MODECLR = 1; // b0 = One stop bit<br>
<br>
// Nastavim preruseni (PIC32MX795F512L.pdf str 123, Sec. 21 UART.pdf, str 23):<br>
IEC1SET = 0b1000000000; // set the UxRXIE bit in the corresponding Interrupt Enable Control register (IEC).<br>
IPC8SET = 0b1100; // Priority 3, b4:2 - Specify the priority (0 - 7, 0 = ISR disable) and subpriority for the interrupt using the UxIP<2:0> and UxIS<1:0><br>
IPC8SET = 0b10; // Subpriority 2, b1:0 - subpriority<br>
<br>
U2STA = 0; // Clear register<br>
U2STACLR = 0b11000000; // b7:6 - Interrupt flag bit is asserted while receive buffer is not empty<br>
U2STASET = 0x1400; // Enable Transmit and Receive<br>
}<br>
<br>
<br>
/**<br>
* Change UART speed on-the-fly<br>
*/<br>
void UART_Sens_B_SetBrg(unsigned char ucBaudRateID) {<br>
unsigned short usBackUp;<br>
<br>
<br>
// Disable Rx and Tx<br>
usBackUp = U2STA & 0x1400; // Backup actuall state.<br>
U2STACLR = 0x1400; // Disable<br>
<br>
// Clear b3 = BRGH<br>
U2MODECLR = 0b1000;<br>
<br>
// Nastavim Baud Rate<br>
switch (psUART_Sens_B->psCfg->ucBaudRateID) {<br>
case UART_HS_9600_ID:<br>
U2BRG = UART_HS_9600_BRG; // Set Baud rate<br>
U2MODESET = UART_HS_9600_BRGH << 3; // b3 = BRGH<br>
break;<br>
case UART_HS_115200_ID:<br>
U2BRG = UART_HS_115200_BRG; // Set Baud rate<br>
U2MODESET = UART_HS_115200_BRGH << 3; // b3 = BRGH<br>
break;<br>
}<br>
<br>
// Reenable UART module:<br>
U2STASET = usBackUp; // Backuped value<br>
return;<br>
}<br>
<br>
<br>
<br>
/**<br>
* UART 2 interrupt handler, the priority set in init function<br>
*/<br>
void __ISR(_UART_2_VECTOR, ipl3) IntUart2Handler(void) {<br>
volatile char cDummy;<br>
<br>
//Is this an RX interrupt?<br>
if (INTGetFlag(INT_SOURCE_UART_RX(UART_B_COMPILER))) {<br>
cDummy = UARTGetDataByte(UART_B_COMPILER); // Get data<br>
INTClearFlag(INT_SOURCE_UART_RX(UART_B_COMPILER)); // Clear the RX interrupt Flag<br>
QueueInsertLast(psQueueB, cDummy); // Save data to my buffer<br>
}<br>
<br>
// We don't care about TX interrupt<br>
if (INTGetFlag(INT_SOURCE_UART_TX(UART_B_COMPILER))) {<br>
INTClearFlag(INT_SOURCE_UART_TX(UART_B_COMPILER));<br>
}<br>
}<br>
_______________________________________________<br>
HW-list mailing list - sponsored by <a href="http://www.HW.cz" rel="noreferrer" target="_blank">www.HW.cz</a><br>
<a href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a><br>
<a href="http://list.hw.cz/mailman/listinfo/hw-list" rel="noreferrer" target="_blank">http://list.hw.cz/mailman/listinfo/hw-list</a><br>
</blockquote></div><br></div>