Self-Balancing Robot
User Guide
34
www.terasic.com
July 12, 2018
temp=IORD(UART_BT_BASE,0x00);
The data width for receiving data register is 32 bits. However, when the command comes from the
Bluetooth, the UART IP only transmit the 8 bits data at one time, so the full instruction needs to be
received multiple times. You can know how many characters have not yet been read via checking
the register data bit 23~16,
number=temp>>16;
If the read data number is not 0, that is, the data is valid. Take the last 8 bits into the array, and then
receive the next 8 bits cyclically, when the received data is 0x0a (which is defined as end of
transmission character). When transferring a control command completed on the mobile app, it
will send out this value for data sending finished, Next to the command comparision, all commands
from the bluetooth are definded in the command.h.
/*
* Command.h
*
*/
#ifndef
COMMAND_H_
#define
COMMAND_H_
#include
"terasic_includes.h"
typedef enum{
CMD_FOWARD=1,
CMD_BACKWARD,
CMD_LEFT,
CMD_RIGHT,
CMD_STOP,
CMD_AKBT,
CMD_ATDM,
CMD_ATUTON,
CMD_ATUTOFF,
}COMMAND_ID;
typedef struct{
char szCommand[10];
int CommandId;
bool bParameter;