BT Pins were not correctly defined in the driver
This commit is contained in:
@@ -12,29 +12,16 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "../../fifo.h"
|
#include "../../fifo.h"
|
||||||
|
|
||||||
#define GPIO_EN_PIN GPIO_Pin_10
|
#define BT_UART USART6
|
||||||
#define GPIO_EN_PORT GPIOG
|
#define BT_UART_CLK RCC_APB2Periph_USART6
|
||||||
|
#define BT_UART_AF GPIO_AF_USART6
|
||||||
|
#define BT_UART_IRQn USART6_IRQn
|
||||||
|
|
||||||
#define GPIO_EN_GPIO_CLK RCC_AHB1Periph_GPIOG
|
#define BT_UART_GPIO_PORT GPIOG
|
||||||
|
#define BT_UART_GPIO_PIN_TX GPIO_Pin_14
|
||||||
#define GPIO_BRTS_GPIO_PIN GPIO_Pin_10
|
#define BT_UART_GPIO_PIN_RX GPIO_Pin_9
|
||||||
#define GPIO_BRTS_GPIO_PORT GPIOB
|
#define BT_UART_GPIO_TX_PinSource GPIO_PinSource14
|
||||||
#define GPIO_BRTS_GPIO_CLK RCC_AHB1Periph_GPIOB
|
#define BT_UART_GPIO_RX_PinSource GPIO_PinSource9
|
||||||
|
|
||||||
#define GPIO_BCTS_GPIO_PIN GPIO_Pin_11
|
|
||||||
#define GPIO_BCTS_GPIO_PORT GPIOB
|
|
||||||
#define GPIO_BCTS_GPIO_CLK RCC_AHB1Periph_GPIOB
|
|
||||||
|
|
||||||
#define BT_UART USART1
|
|
||||||
#define BT_UART_CLK RCC_APB2Periph_USART1
|
|
||||||
#define BT_UART_AF GPIO_AF_USART1
|
|
||||||
#define BT_UART_IRQn USART1_IRQn
|
|
||||||
|
|
||||||
#define BT_UART_GPIO_PIN_TX GPIO_Pin_6
|
|
||||||
#define BT_UART_GPIO_PIN_RX GPIO_Pin_7
|
|
||||||
#define BT_UART_GPIO_TX_PinSource GPIO_PinSource6
|
|
||||||
#define BT_UART_GPIO_RX_PinSource GPIO_PinSource7
|
|
||||||
#define BT_UART_GPIO_PORT GPIOB
|
|
||||||
|
|
||||||
Fifo<200> btTxFifo;
|
Fifo<200> btTxFifo;
|
||||||
Fifo<200> btRxFifo;
|
Fifo<200> btRxFifo;
|
||||||
@@ -44,30 +31,8 @@ int bt_open()
|
|||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
USART_InitTypeDef USART_InitStructure;
|
USART_InitTypeDef USART_InitStructure;
|
||||||
|
|
||||||
RCC_AHB1PeriphClockCmd( GPIO_BRTS_GPIO_CLK, ENABLE);
|
|
||||||
RCC_AHB1PeriphClockCmd( GPIO_EN_GPIO_CLK, ENABLE);
|
|
||||||
RCC_APB2PeriphClockCmd(BT_UART_CLK, ENABLE);
|
RCC_APB2PeriphClockCmd(BT_UART_CLK, ENABLE);
|
||||||
|
|
||||||
//PG10:as bluetooth EN
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_EN_PIN;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
||||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
|
||||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
|
||||||
GPIO_Init(GPIO_EN_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
GPIO_SetBits(GPIO_EN_PORT, GPIO_EN_PIN);
|
|
||||||
|
|
||||||
//PB10,PB11
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_BRTS_GPIO_PIN | GPIO_BCTS_GPIO_PIN;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
||||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
|
||||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
|
||||||
GPIO_Init(GPIO_BRTS_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
//PB6:as TXD
|
|
||||||
//PB7:as RXD
|
|
||||||
GPIO_PinAFConfig(BT_UART_GPIO_PORT, BT_UART_GPIO_TX_PinSource, BT_UART_AF);
|
GPIO_PinAFConfig(BT_UART_GPIO_PORT, BT_UART_GPIO_TX_PinSource, BT_UART_AF);
|
||||||
GPIO_PinAFConfig(BT_UART_GPIO_PORT, BT_UART_GPIO_RX_PinSource, BT_UART_AF);
|
GPIO_PinAFConfig(BT_UART_GPIO_PORT, BT_UART_GPIO_RX_PinSource, BT_UART_AF);
|
||||||
|
|
||||||
@@ -97,8 +62,6 @@ int bt_open()
|
|||||||
USART_Cmd(BT_UART, ENABLE);
|
USART_Cmd(BT_UART, ENABLE);
|
||||||
USART_ITConfig(BT_UART, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(BT_UART, USART_IT_RXNE, ENABLE);
|
||||||
|
|
||||||
GPIO_ResetBits(GPIO_EN_PORT, GPIO_EN_PIN); //open bluetooth
|
|
||||||
|
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = BT_UART_IRQn;
|
NVIC_InitStructure.NVIC_IRQChannel = BT_UART_IRQn;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
|
||||||
@@ -139,8 +102,6 @@ int bt_write(void *buffer, int len)
|
|||||||
for (int i=0; i<len; ++i) {
|
for (int i=0; i<len; ++i) {
|
||||||
btTxFifo.push(data[i]);
|
btTxFifo.push(data[i]);
|
||||||
}
|
}
|
||||||
GPIO_ResetBits(GPIO_EN_PORT, GPIO_EN_PIN);
|
|
||||||
GPIO_ResetBits(GPIO_BRTS_GPIO_PORT, GPIO_BRTS_GPIO_PIN);
|
|
||||||
USART_ITConfig(BT_UART, USART_IT_TXE, ENABLE);
|
USART_ITConfig(BT_UART, USART_IT_TXE, ENABLE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -149,7 +110,6 @@ int bt_read(void *buffer, int len)
|
|||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
uint8_t *data = (uint8_t *)buffer;
|
uint8_t *data = (uint8_t *)buffer;
|
||||||
GPIO_ResetBits(GPIO_BCTS_GPIO_PORT, GPIO_BCTS_GPIO_PIN);
|
|
||||||
while (1) {
|
while (1) {
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
if (!btRxFifo.pop(byte))
|
if (!btRxFifo.pop(byte))
|
||||||
@@ -162,6 +122,5 @@ int bt_read(void *buffer, int len)
|
|||||||
|
|
||||||
int bt_close()
|
int bt_close()
|
||||||
{
|
{
|
||||||
GPIO_SetBits(GPIO_EN_PORT, GPIO_EN_PIN);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user