2012-08-31 11:51 AM
Hi,
at the moment I'm using the following code to recieve a byte:char
ReceivedData = NULL;
void
main() {
.
.
.
while
(1){
/* Wait until a byte is received */
while
(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET)
{
}
/* read byte and print via usart2 it */
ReceivedData = USART_ReceiveData(USART2);
printf
(
''Positionen: %d \r\n''
, ReceivedData);
//abbort if 3 received
if
(ReceivedData == 3)
break
;
}
.
.
}
I now want to recieve more then 1 byte and store it an recieve Buffer ''RXBUFF[]''.
Because I want to send a byte array from my pc to the controller and then I want to deserialze the data to int16 or int32 ...
How can i achieve that?
how can I recieve my bytearray with the stm32f103 ?
WR
Alex
#usart-stm32-loopback #usart-stm32
2012-08-31 12:07 PM
char RXBUFF[16];
void main()
{
int i = 0;
while(1)
{
/* Wait until a byte is received */
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
/* read byte and print via usart2 it */
RXBUFF[i++] = USART_ReceiveData(USART2);
if (i >= 16) i = 0;
}
}
2012-08-31 01:15 PM
Thank you clive,
can you show me how i can ''printf'' (loopback) the Array to check that everything transmitted complete ? printf(''Data Recieved: %c'', RXBUFF); doesnt work2012-08-31 01:41 PM
I want to make an easy loop back function and after implementing ur code it looks like this but i doesnt work.
while
(1)
{
//Bytes RECV ( RXBUFF[248] )
/* Wait until a byte is received */
while
(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
{}
RXBUFF[j++] = USART_ReceiveData(USART2);
if
(j >= 248)
j = 0;
//Bytes SEND ( RXBUFF[248] )
while
( j>= 248)
{
USART_SendData(USART2, RXBUFF[j]);
j++;
/* Loop until the end of transmission */
while
(USART_GetFlagStatus(IMU_COM2, USART_FLAG_TC) == RESET)
{}
}
printf
(
''all bytes recv. and sended
''
);
}
2012-08-31 02:18 PM
while(1)
{
/* Wait until a byte is received */
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
RXBUFF[j] = USART_ReceiveData(USART2);
if (USART_GetFlagStatus(USART2, USART_FLAG_TXE) != RESET)
USART_SendData(USART2, RXBUFF[j]);
j++;
if (j >= 248)
j = 0;
}
2012-08-31 05:08 PM
Thank you clive for helping me,
I implemented your code in a function:void
GetScrewPositions()
{
printf
(
''ready to get Data
''
);
int
j =0;
while
(1)
{
//Wait until a byte is received
while
(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
RXBUFF[j] = USART_ReceiveData(USART2);
if
(USART_GetFlagStatus(USART2, USART_FLAG_TXE) != RESET)
USART_SendData(USART2, RXBUFF[j]);
j++;
if
(j >= 248)
j = 0;
printf
(
''All bytes recieved and sended
''
);
}
}
IT WORKS NOW!
do you know how to deserialize Data in the quickest way on a stm32 ?
2012-09-01 03:03 PM
do you know how to deserialize Data in the quickest way on a stm32 ?
Depends on what the data looks like, your could do it as a state machine in an interrupt, or build a line buffer and pass it off to a decoding/parsing task.2012-09-01 04:29 PM
hi clive,
I mean, how can I write my recieved data RXBUFF[248]
to my variables.
Because I recieve 60x int32_t ...
and RXBUFFER containts only bytes. like 2F00 = uint16 -> 47
you know what I mean.
I want to deserialize my data to my datatypes like this.
int32 mynumber1 = RXBUFFER[0] // 4 bytes of rxbuffer parsed to int32 number1
int32 mynumber2 = RXBUFFER[4]
...
int32 mynumber60 = RXBUFFER[240]
Is there a way for this ?
I really thank you for helping me !
2012-09-01 05:35 PM
At bit kludgy but
int32 mynumber1 = *((int32 *)&RXBUFFER[0]); // 4 bytes of rxbuffer parsed to int32 number1 int32 mynumber2 = *((int32 *)&RXBUFFER[4]); or marginally less int32 *array32 = (int32 *)RXBUFFER; number1 = array32[0]; number2 = array32[1];2012-09-01 07:46 PM
works perfect! thank you !
one last question. I just want to recieve my 248 bytes now. I modified the function a little bit. And it works so far when im sending a file with exact 248bytes.#define buflgth 248 //my byte count
int j =0;
int cnt = 0;
while(cnt <= buflgth-1)
{
//Wait until a byte is received
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
RXBUFF[j] = USART_ReceiveData(USART2);
cnt++;
j++;
if (j >= buflgth)
j = 0;
}
is there an easier or better way?
where can I find a Book about stm.. or other question where do you learned everything about stm32 clive? ... ;)
thank you very much!!!!