2017-05-26 03:08 PM
Hello everyone,
I started programming for one of my student projects but I am pretty hung up on the USART2 configuring. I have worked with Arduinos before, but I must admit that STM32 is a complete different level
:)
I am using the STM32F303VCT6 on the DiscoveryBoard with the STLink2 included. I am trying to figure out this USART stuff but I can not make much sense of all the data sheets. I am a aerospace engineer with some C programming experience, but working with those cryptic datasheets is completely new to me.
I really hope some of you guys have some patience and motivation to help me out with my project. Basically I need to connect my PC with the STM (USART2) and the STM with a Camera(UART1). The STM32 should send some hex characters to the cam so it makes a picture and after that receive the pic and send it to the pc.
I am stuck at the beginning and need to activate the USART2 connection. I have connected an FTDI to USART2 but and try to send characters with hterm to start an interrupt, but nothing happens. Obviously it is my code, but I do not know whats wrong. I guess it is more than one mistake
:)
At first I just want to send a character from PC and turn an LED on if the character is received with the interrupt. The code is here:I uploaded the code here:
If more Information is needed don't hesitate to ask.
Thanks in advance,
Kevin Dominic
2017-06-11 11:41 AM
Thanks a lot again,
and again I am a little bit further
Now I can send the hex code to my cam and I receive characters, but somehow a weird mixture of them...
Here is the current code first:
When I write 'ON'(0x4F 0x4E) on my pc per hterm I send a command which makes a picture to the JPEG_Cam. I am supposed to receive exactly this string of code: (hex) 76 00 36 00 00.
It the system always responds like this:
send ON the first time: no response
send ON the second time: 00 00
send On the third time and after: mixture of 00, 56, 76, 01, sometimes even 4F, 4E
it seems to always be the same but with different combos of numbers. sometimes only 2, sometimes all 5 characters. Am I writing in the wrong register? Or is the setup to write and read in usart1 wrong? I can not explain this to me...
Help is like always appreciated,
Thanks,
Kevin
2017-06-12 09:32 AM
Have you tried a scope or a logic analyzer to discern between between actual bus events (requests, responses), and events (bytes) you see on the target ?
2017-06-12 12:15 PM
//senden der Empfangenen Daten
for (int k = 0; k < count_usart1; ++k)
USART2->TDR = rx_usart1_buffer[k];
�?�?�?
What did I tell you about blindly jamming data into the USART? Try to take onboard advice explicitly given, otherwise I waste my time.
Your code doesn't recognize or resynchronize if the 'ON' pair shift in the buffer.
Try to do simple things first before moving on to complex interactions, especially with interrupts and buffering which you don't appear to grasp. Just grabbing code you don't understand and then banging at it randomly will not solve problems.
Try something like this
void USART1_SendBuffer(int Size, char *Buffer)
{
while(Size--)
{
while(USART1->ISR & USART_ISR_TXE); // Wait for an EMPTY USART buffer
USART1->TDR = *Buffer++; // Send ONE character to FILL USART buffer
}
}
main()
{
...
// NO IRQs enabled or setup, just the USARTs
while(1)
{
if (USART2->ISR & USART_ISR_RXNE)// One character available
{
rx_usart2_buffer[0] = rx_usart2_buffer[1]; // Previous
rx_usart2_buffer[1] = USART2->RDR; // Current
if ((rx_usart2_buffer[0] == 'O') && (rx_usart2_buffer[1] == 'N'))
{
tx_usart1_buffer[0] = 0x56;
tx_usart1_buffer[1] = 0x00;
tx_usart1_buffer[2] = 0x36;
tx_usart1_buffer[3] = 0x01;
tx_usart1_buffer[4] = 0x00;
USART1_SendBuffer(5, tx_usart1_buffer);
}
}
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?