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 variabletypeAnnotation
g_autoupintAutomatically report
manydisplaychar[80]Report data string
updatachar[80]Store the final data
lspeedchar[10]Left motor speed string
rspeedchar[10]Right motor speed strings
daccelchar[10]Acceleration string
dgyrochar[10]Gyroscope data string
csbchar[10]Ultrasonic distance string
vichar[10]Electric string
newLineReceivedu8New Line Receive Label
numintInput string length
startBitu8Agreement starting
int9numint9th integer value
inputStringu8[80]Receive input string
ProtocolStringu8[80]Protocol string
g_newcarstateenCarStateCar status
PID_Originalfloat[6]PID initial value array
piddisplaychar[50]PID display string
charkpchar[10]Proportional gain KP string
charkdchar[10]Microcar gain KD string
charkspchar[10]Speed ​​ring kp string
charksichar[10]Speed ​​ring Ki string
charktpchar[10]Steering ring kp string
charktdchar[10]Steering ring kd string

Macro definition

Macro definitionvalueAnnotation
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 valuetype
nonevoid

bluetooth_send_char(uint8_t ch)

Send a character

parametertypeAnnotation
chuint8_tThe characters to be sent
Return valuetype
nonevoid

UART5_Send_ArrayU8(uint8_t *BufferPtr, uint16_t Length)

Send a byte array

parametertypeAnnotation
BufferPtruint8_t*Data pointer to be sent
Lengthuint16_tData length
Return valuetype
nonevoid

USART5_Send_Byte(unsigned char byte)

Send a byte

parametertypeAnnotation
byteunsigned charThe bytes to be sent
Return valuetype
nonevoid

bluetooth_send_string(char *s)

Send string

parametertypeAnnotation
schar*String to be sent
Return valuetype
nonevoid

Init_PID(void)

Initialize PID parameters

Return valuetype
nonevoid

ResetPID(void)

PID parameters when resumed opening

Return valuetype
nonevoid

deal_bluetooth(uint8_t rxbuf)

Process the receiving Bluetooth data

parametertypeAnnotation
rxbufuint8_tReceived data
Return valuetype
nonevoid

ProtocolCpyData(void)

Copy protocol data

Return valuetype
nonevoid

Protocol(void)

Analysis protocol data

Return valuetype
nonevoid

StringFind(const char *pSrc, const char *pDst)

Find sub -string

parametertypeAnnotation
pSrcconst char*Source string
pDstconst char*Target string
Return valuetype
Find starting indexint

CalcUpData(void)

Calculate and update the report data

Return valuetype
nonevoid

SendAutoUp(void)

Report data automatically

Return valuetype
nonevoid

ProtocolGetPID(void)

Get PID parameters

Return valuetype
nonevoid

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);
    }
}