Bluetooth(Bluetooth)
1.bsp_bluetooth.c The file is stored in the Bluetooth basic driver file
2.app_bluetooth.c The file is stored in the file of the car application Bluetooth
Global variable
| Global variable | type | Annotation |
|---|---|---|
| g_autoup | int | Automatically report |
| manydisplay | char[80] | Report data string |
| updata | char[80] | Store the final data |
| lspeed | char[10] | Left motor speed string |
| rspeed | char[10] | Right motor speed strings |
| daccel | char[10] | Acceleration string |
| dgyro | char[10] | Gyroscope data string |
| csb | char[10] | Ultrasonic distance string |
| vi | char[10] | Electric string |
| newLineReceived | u8 | New Line Receive Label |
| num | int | Input string length |
| startBit | u8 | Agreement starting |
| int9num | int | 9th integer value |
| inputString | u8[80] | Receive input string |
| ProtocolString | u8[80] | Protocol string |
| g_newcarstate | enCarState | Car status |
| PID_Original | float[6] | PID initial value array |
| piddisplay | char[50] | PID display string |
| charkp | char[10] | Proportional gain KP string |
| charkd | char[10] | Microcar gain KD string |
| charksp | char[10] | Speed ring kp string |
| charksi | char[10] | Speed ring Ki string |
| charktp | char[10] | Steering ring kp string |
| charktd | char[10] | Steering ring kd string |
Macro definition
| Macro definition | value | Annotation |
|---|---|---|
| run_car | '1' | Advance command |
| back_car | '2' | Back Command |
| left_car | '3' | Turn left command |
| right_car | '4' | Right turn command |
| stop_car | '0' | Stop command |
method
bluetooth_init(void)
Initialize Bluetooth Module
| Return value | type |
|---|---|
| none | void |
bluetooth_send_char(uint8_t ch)
Send a character
| parameter | type | Annotation |
|---|---|---|
| ch | uint8_t | The characters to be sent |
| Return value | type |
|---|---|
| none | void |
UART5_Send_ArrayU8(uint8_t *BufferPtr, uint16_t Length)
Send a byte array
| parameter | type | Annotation |
|---|---|---|
| BufferPtr | uint8_t* | Data pointer to be sent |
| Length | uint16_t | Data length |
| Return value | type |
|---|---|
| none | void |
USART5_Send_Byte(unsigned char byte)
Send a byte
| parameter | type | Annotation |
|---|---|---|
| byte | unsigned char | The bytes to be sent |
| Return value | type |
|---|---|
| none | void |
bluetooth_send_string(char *s)
Send string
| parameter | type | Annotation |
|---|---|---|
| s | char* | String to be sent |
| Return value | type |
|---|---|
| none | void |
Init_PID(void)
Initialize PID parameters
| Return value | type |
|---|---|
| none | void |
ResetPID(void)
PID parameters when resumed opening
| Return value | type |
|---|---|
| none | void |
deal_bluetooth(uint8_t rxbuf)
Process the receiving Bluetooth data
| parameter | type | Annotation |
|---|---|---|
| rxbuf | uint8_t | Received data |
| Return value | type |
|---|---|
| none | void |
ProtocolCpyData(void)
Copy protocol data
| Return value | type |
|---|---|
| none | void |
Protocol(void)
Analysis protocol data
| Return value | type |
|---|---|
| none | void |
StringFind(const char *pSrc, const char *pDst)
Find sub -string
| parameter | type | Annotation |
|---|---|---|
| pSrc | const char* | Source string |
| pDst | const char* | Target string |
| Return value | type |
|---|---|
| Find starting index | int |
CalcUpData(void)
Calculate and update the report data
| Return value | type |
|---|---|
| none | void |
SendAutoUp(void)
Report data automatically
| Return value | type |
|---|---|
| none | void |
ProtocolGetPID(void)
Get PID parameters
| Return value | type |
|---|---|
| none | void |
Example
#include "bsp_bluetooth.h"
int main() {
bluetooth_init();
bluetooth_send_string("Hello Yahboom!\n");
while(1);
}
// When Bluetooth receives the message, it will trigger the interruption
void UART5_IRQHandler(void) {
uint8_t Rx5_Temp;
if (USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
Rx5_Temp = USART_ReceiveData(UART5);
bluetooth_send_char(Rx5_Temp);
}
}