2018-06-19 06:00 AM
hi everyone,
i am using stm32f103 mcu and silicon labs' bgm113 ble module in ncp mode. bgm113 sends datas over uart and mcu handles the operation. in ncp mode there two types receiving data: command and event. command data is response to commands and that type is works good. but event data comes when event trigered and unexpected time and that is creates bugs sometimes. Also if i connect more than 2 modules problems occured again. a data packet comes and while mcu is busy (for example sending data to internet) another data packet comes too. So mcu doesn't know previous packet. i tried receive data with two dimension receive buffer like circular buffer i failed again. is there anyone worked bgm modules or what can you give me algorithm offer about that ?2018-06-19 04:36 PM
you have two serial devices on two different UARTS ?
you have DMA circular mode on both UARTS with a buffer of 1024 bytes each ?
You will receive everything sent to either port
So what is the problem ?
2018-06-20 02:30 AM
yes i have two serial devices and circular dma mode on both uarts. there is no cr+lf byte or anything in bgm's data package. i use a 3ms timer interrupt to understand receiving finished. when a receiving finishes i reset receiveBufferIndex. so if any package comes before other package implemented, i lose previous package. Actually problem is that loosing previous data.
i have not a problem receiving data. for example i received data from bgm module, and i will send to server over gsm. mcu tries to connect server and send data, sometimes it takes 2-3 seconds, in that 2 seconds i may take more than one data package from bgm modules. when sending data to server is finishes, mcu looks what received from bgm module but it knows just last one, and it doesn't know anything about previous data.i hope it is understandable now and sorry for english. thanks for your replyy
2018-06-20 04:44 AM
maybe change your approach a little.
I track the DMA buffer size, do you know the incoming packet length ?
with this code style, I can peek at the receive buffer before I receive it.
lets say you are in the mS systick process, you can call these ;
char readableU1(void) { // incoming bytes ptr is calculated from the DMA pointer
U1RxBufferPtrIN = U1RxBufSize - huart1.hdmarx->Instance->CNDTR; return (U1RxBufferPtrIN - U1RxBufferPtrOUT) & (U1RxBufSize-1); // bufSize must be 2^n // unread buffer length}char getc1(void) { char Rxbyte = Usart1RxDMABuffer[U1RxBufferPtrOUT++]; if (U1RxBufferPtrOUT >= U1RxBufSize) U1RxBufferPtrOUT = 0; return Rxbyte;}char peekRxU1(int offset) { // offset of zero returns the next byte to be read
int relativePtr = (U1RxBufferPtrOUT+ offset) & (U1RxBufSize-1); // bufSize must be 2^n
char PeekRx= Usart1RxDMABuffer[relativePtr ]; // just looking Don't increment pointerreturn PeekRx;
}
you know the current output pointer U1RxBufferPtrOUT
and you can read the current DMA input pointer U1RxBufferPtrIN
lets say your frame is 3- 10 bytes long
currentUnreadBufferSize = (U1RxBufferPtrIN - U1RxBufferPtrOUT) & (U1RxBufSize-1); // bufSize must be 2^n
2018-06-20 08:04 AM
i don't know
incoming packet length, every time it changes. it is not fixed length. if i get clearly what you mean i have to know every package's length and start adress. when i read i must use next data's adress pointer and length.
2018-06-20 08:25 AM
>>
i have to know every package's length
You might have to be able to figure out the size on the fly, and separate individual packets.
If that is all based on 'timing', then you'd likely want to use the interrupt to process each byte at arrival, and manage a timeout count down.
2018-06-20 08:34 AM
yes, i open timer when a byte comes, if there is no new byte in 3ms, timer interrupt runs and says package is finished.