2013-05-26 09:21 PM
I am trying for now to send 600 001 bytes to PC from stm32f4 discovery board.
below is how USART configured:uint32_t config_usart3(
void
)
{
//=============================================================================
// USART3 Related configuration
//=============================================================================
// enable clock
RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
// 1) Setting UE, amd M bits
USART3-> CR1 |= 0x2000;
// UE = 1
// 2) Programming number of stop bits if needed
// 3) Enable DMA if needed
// 4) set the Baud Rate
// BAUD = *** / ( 8 * (2 - OVER8) * USARTDIV )
// *** = 42MHz,
// OVER8 = 0
// Choose BAUD = 115200
// then: USARTDIV = *** / ( 8 * (2 -OVER8) * BAUD = 75
// BRR = (22 << 4) | ( 0.75 * 16) = 364,
// or: BRR = *** / BAUD = 42MHz / 115200 = 364
USART3->BRR = 364;
// enable transmitter
USART3->CR1 |= USART_CR1_TE;
// enable receiver
USART3->CR1 |= USART_CR1_RE;
// enable CTS/RTS
USART3->CR3 |=
(
USART_CR3_CTSE |
USART_CR3_RTSE
);
return
0;
}
Below is how GPIO port relevant to USART1 configured:
//=============================================================================
// GPIOD configuration
//=============================================================================
// enable GPIOD clock
((RCC_TypeDef *)(RCC_BASE))->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
// Alternate Function
((GPIO_TypeDef *)(GPIOD_BASE))->MODER |=
(GPIO_MODER_MODER9_1 |
// Alternate Function, USART3_RX
GPIO_MODER_MODER8_1 |
// Alternate Function, USART3_TX
GPIO_MODER_MODER11_1 |
// Alternate Function, USART3_CTS
GPIO_MODER_MODER12_1
// Alternate Function, USART3_RTS
);
// Output type
GPIOD->OTYPER = 0;
// Speed type
((GPIO_TypeDef *)(GPIOD))->OSPEEDR |=
(GPIO_OSPEEDER_OSPEEDR8_1 |
// USART3 TX 50 MHz
GPIO_OSPEEDER_OSPEEDR9_1 |
// USART3 RX 50 MHz
GPIO_OSPEEDER_OSPEEDR11_1 |
// USART3 CTS 50 MHz
GPIO_OSPEEDER_OSPEEDR12_1
// USART3 RTS 50 MHz
);
// Push/Pull for USART3
GPIOD->PUPDR = 0;
((GPIO_TypeDef *)(GPIOD_BASE))->PUPDR |=
(
GPIO_PUPDR_PUPDR8_0 |
// Pull-Up, USART3 TX
GPIO_PUPDR_PUPDR9_0 |
// Pull-Up, USART3 RX
GPIO_PUPDR_PUPDR11_0 |
// Pull-Up, USART3 CTS
GPIO_PUPDR_PUPDR12_0
// Pull-Up, USART3 RTS
);
((GPIO_TypeDef *)(GPIOD_BASE))->AFR[1] |= (
(7 << ((8 - 8) << 2)) |
// USART3 TX, AF7
(7 << ((9 - 8) << 2)) |
// USART3 RX, AF7
(7 << ((11 - 8) << 2)) |
// USART3 CTS, AF7
(7 << ((12 - 8) << 2))
// USART3 RTS, AF7
);
and below is how I send my bytes:
uint8_t mem_read(USART_TypeDef *USART_ID )
{
uint32_t i=0;
// loop var
//send read buffer to USART
for
(i=0;iSR & USART_SR_TXE)) );
USART_ID->DR = 0x5d;
// sending a byte
// check if TC bit is set
while
((!(USART_ID->SR & USART_SR_TC)) );
}
return
0;
}
Using WinXP, with FTDI cable and its drivers, cable was loopbacked and seems to work.
What happens is, on the PC end I get my 600001 bytes 5-6 times out of 10, in other words, a lot of times I end up missing couple thousand bytes or s (I get something like 597 953 bytes etc).
Not sure what else did I do on the STM32 part?
as you see I check for TXE, and TC(although checking TC might not be needed that much)
I also set up the stm32 in CTS/RTS mode, as well as the PC terminal emulator program.
again,.. I do get 600001 bytes but not all the time! And I am curious what else could be wrong?
2013-05-27 06:30 AM
Yeah, I'd probably lose the TC, and add stop bits if I had a synchronization issue.
You might want to look at your Windows side app, and it's ability to efficiently sink data. ie not a terminal app dumping received data to the screen. 600001 sounds like a lot of data to transmit over a serial link without some sort of protocol with intrinsic validity checking or flow control. Again, I don't think a terminal app is appropriate for testing such a link.2013-05-27 07:32 AM
and how about adding something like MAX232, and do STM32--->RS-232---->(USB-RS-232 Adapter) ?
and keeping the same way of doing this?reason I say that is, I kind of suspect that my USB FTDI cable does not handle CTS/RTS properly thats why I loose data between it and PC, what other methods would be for raw data read using Serial USART? (reliable, without loosing bytes)2013-05-27 07:33 AM
or for example doing something like STM32 USART---> RS-485---> usb adapter?
2013-05-27 07:57 AM
Which FTDI cable? You should be able to connect the 3V TTL/CMOS type up directly.
http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm
I'm not sure why you think RS232 or RS485 would be intrinsically more reliable in this situation? You want to be looking a layering a protocol on top of the physical transport.2013-05-27 09:21 AM
2013-05-27 09:36 AM