hey,
(code is below)
I'm using UART to communicate with the computer (using both C# in visual studio and hyperterminal). First, I made the parity bit even and one stop bit, and everything was working fine.
next I tried to change the parity bit to odd, and when sending one byte (one char) from PC it works fine, but when I send two bytes something went wrong and I sometimes gets framing error and sometimes parity error (usually both in same). the first char is detected well and the second is detected as something which I didn't send at all. when the KL25Z is sending chars to the PC, I get part of the letters, and the others are labeled with '?'
the question is why this can happen when the only change between the even option and the odd option is the bit PT in UART0_C2?
another problem occurs when I set 2 stop bit (even in parity)- it's doing the same a I described with odd situation, but this time when sending from the KL25Z to the PC, the PC gets nothing.
worth mentioning: the setting of the UART in the PC and the KL25Z are changing as they should.
here is the the code I wrote for changing the setting the the UART:
/********************************************************************
changeUARTsetting- receive from PC the wanted bound rate, parity bit and stop bit and change the UART settings.
After receiving the info, KL25Z will send ACK char for PC.
*********************************************************************/
void changeUARTsetting(){
char settings_info[3]; //info array; settings_info[0]=bound rate, settings_info[1]=parity bit, settings_info[2]=stop bit.
UART0_C2 &= ~UART0_C2_RIE_MASK; //disable receiver interrupt
/* Wait until character has been received -for first initial*/
while (!(UART_S1_REG(UART0_BASE_PTR) & UART_S1_RDRF_MASK));
settings_info[0]=uart_getchar (UART0_BASE_PTR);
settings_info[1]=uart_getchar (UART0_BASE_PTR);
settings_info[2]=uart_getchar (UART0_BASE_PTR);
sendACK((char)GenralACK);
while(!(UART_S1_REG(UART0_BASE_PTR) & UART_S1_TC_MASK)); /* Wait until trr is completed */
//disable transmitter and receiver
UART0_C2 &= ~(UART_C2_TE_MASK
| UART_C2_RE_MASK );
switch (settings_info[0]){
case '1':
Uart0_Br_Sbr(CORE_CLOCK/2/1000, SDA_SERIAL_BAUD2400);
break;
case '2':
Uart0_Br_Sbr(CORE_CLOCK/2/1000, SDA_SERIAL_BAUD9600);
break;
case '3':
Uart0_Br_Sbr(CORE_CLOCK/2/1000, SDA_SERIAL_BAUD19200);
break;
case'4':
Uart0_Br_Sbr(CORE_CLOCK/2/1000, SDA_SERIAL_BAUD38400);
break;
}
switch(settings_info[1]){
case '0': //no parity
UART0_C1 &= ~(UART0_C1_PE_MASK | UART0_C1_M_MASK); //set also 8 bit data
break;
case '1': //even parity
UART0_C1 |= UART0_C1_PE_MASK | UART0_C1_M_MASK; //set also 9 bit data
UART0_C1 &= ~UART_C1_PT_MASK;
break;
case '2': //odd bit
UART0_C1 |= UART0_C1_PE_MASK |UART_C1_PT_MASK | UART0_C1_M_MASK; //set also 9 bit data
break;
}
switch(settings_info[2]){
case '1': //one stop bit
UART0_BDH &= ~UART0_BDH_SBNS_MASK;
break;
case '2': //two stop bit
UART0_BDH |= UART0_BDH_SBNS_MASK;
break;
}
// Enable Transmitter, Receiver, Receive interrupt
UART0_C2 = UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK | UART_C2_RIE_MASK; // Enable Transmitter, Receiver, Receive interrupt
}
thank you