cancel
Showing results for 
Search instead for 
Did you mean: 

USB virtual com PORT example problem

lior
Associate II
Posted on December 01, 2008 at 06:19

USB virtual com PORT example problem

1 REPLY 1
lior
Associate II
Posted on May 17, 2011 at 12:54

hi,

i found that virtual com exampe doesnt work properly.

1.

in the function uart_config()

these lines

/*set the data type : only 8bits and 9bits is supported */

switch (linecoding.datatype)

{

case 0x07:

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

break;

case 0x08:

USART_InitStructure.USART_WordLength = USART_WordLength_9b;

break;

default :

{

USART_Config_Default();

return (FALSE);

}

}

not correct because if the data is 8 bits this function choose 9bit data without to check if there is definition of parity bit.

i tried to work with serial port 9600 8 bit data and no parity and the data was wrong because it was defined as USART_WordLength_9b in spite of the data is 8 bit without parity.

this problem back also in USART_To_USB_Send_Data function

in these lines:

if (USART_InitStructure.USART_WordLength == USART_WordLength_8b)

{

buffer_in[count_in] = USART_ReceiveData(USART1) & 0x7F;

}

else if (USART_InitStructure.USART_WordLength == USART_WordLength_9b)

{

buffer_in[count_in] = USART_ReceiveData(USART1);

}

not correct again because there is mask on the data even if there is no parity bit.

it easy to fix this with adding of checking of the existance of parity bit in the definition of the com port.

2.

in you try to work with 9600 the uart is too slow and there is lost of data .

for example in the main()

while (1)

{

if ((count_out != 0) && (bDeviceState == CONFIGURED))

{

USB_To_USART_Send_Data(&buffer_out[0], count_out);

count_out = 0;

}

}

if you got from the usb 10 bytes for example it takes 1 ms for byte to send it and then there is this line:

count_out = 0;

count_out is updated in the usb interrupt so when you reset it from the main loop you lose data.

3. and the last problem is in

USB_To_USART_Send_Data()

these lines:

for (i = 0; i < Nb_bytes; i++)

{

USART_SendData(USART1, *(data_buffer + i));

}

you should add this line before the send to the uart in order to avoid lost of data:

/* Wait until end of transmit */

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)

{

}