Table of contents
Communication Protocol Selection
Host computer configuration implementation
Lower computer code implementation
Demonstration of communication effect
foreword
The method of uploading variables through VOFA and displaying them as waveforms for debugging is introduced above. VOFA uploads floating points, and a floating point needs 4 bytes to represent, which is not a small burden for the serial port that is not very fast. And it is not friendly to the fixed-point MCU to upload data. For the method of VOFA uploading data, refer to the link below:
Here is an introduction to how the anonymous assistant displays the data waveform of the lower computer. In the future development, you can choose the appropriate tool according to the actual situation and usage habits.
Communication Protocol Selection
Here select the flexible format frame mode, refer to the protocol introduction document of the software.
In actual use, because you are not familiar with the protocol, you can't step on the pitfalls. Here is a summary:
The following is a frame of data that meets the communication protocol:
Frame header: 0xAB one byte, fixed, if changed to other, the communication will fail and the waveform cannot be displayed
Source address: one byte, write whatever you want, 0x00 is also fine, it will not affect the waveform display
Target address: one byte, write casually, without affecting the waveform display
Function code: one byte, here is 0xF1, which needs to correspond to the host computer
Data length: two bytes, low byte first, as follows, there are 6 transmitted data
Data content: The following 6-11 are the length of the data to be transmitted, a total of 6, used to represent 3 int16_t variables. It depends on the number of transfer variables
The sum checksum and additional checksum are the two-byte checksums calculated through the transmitted content
The calculation method is as follows:
Host computer configuration implementation
The configuration here displays the three-phase current, which are represented by int16_t, as described in the protocol above, the configuration only needs to add data.
After configuring the data of 0xF1, click the small wrench again, find 0xF1#0:IA-IC, and click OK to display the waveform normally.
If there is no waveform, click the run button in the lower right corner again
Lower computer code implementation
Simply define an array, refer to the communication protocol, and define a send function
static uint8_t tempData[14] = {0xAB,0xFE,0x05,0xF1,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void UART_Debug(void);
Put the data to be transmitted in the specified location, simple and rude, just call the send function in the periodic task or interrupt.
void UART_Debug(void)
{
uint16_t flen = tempData_NM[4]+tempData_NM[5]*256;
uint8_t sumcheck=0;
uint8_t addcheck=0;
tempData_NM[6] =((int16_t)((Ia_A)*100)&0xFF);
tempData_NM[7] =((int16_t)((Ia_A)*100)>>8);
tempData_NM[8] =((int16_t)((Hall_Angle)*100)&0xFF);
tempData_NM[9] = ((int16_t)((Hall_Angle)*100)>>8);
tempData_NM[10] =((int16_t)((Hall_Speed)*10)&0xFF);
tempData_NM[11] =((int16_t)((Hall_Speed)*10)>>8);
for(uint16_t i=0;i<(flen+6);i++)
{
sumcheck+=tempData_NM[i];
addcheck+=sumcheck;
}
tempData_NM[12]=(uint8_t)sumcheck;
tempData_NM[13]=(uint8_t)addcheck;
HAL_UART_Transmit_DMA( &huart2, (uint8_t *)tempData_NM, 14);
}
Demonstration of communication effect
Anonymous assistant displays current waveform
Summarize
VOFA and the anonymous assistant have their own advantages and disadvantages, and both can support higher baud rates. There is no detailed comparison here, but for engineering applications, as long as the application needs are met. Thanks to VOFA and anonymous authors for sharing these tools, which greatly improves the development efficiency of engineers.