diff --git a/Anaren_uart_example/Doc/A20737A-736703.pdf b/Anaren_uart_example/Doc/A20737A-736703.pdf new file mode 100644 index 0000000..c67e23d Binary files /dev/null and b/Anaren_uart_example/Doc/A20737A-736703.pdf differ diff --git a/Anaren_uart_example/Doc/AnarenBCM20737.pdf b/Anaren_uart_example/Doc/AnarenBCM20737.pdf new file mode 100644 index 0000000..481f0d0 Binary files /dev/null and b/Anaren_uart_example/Doc/AnarenBCM20737.pdf differ diff --git a/Anaren_uart_example/Doc/BCM20737 - Single-Chip Bluetooth Low Energy-Only System-On-Chip with Support for Wireless Charging.pdf b/Anaren_uart_example/Doc/BCM20737 - Single-Chip Bluetooth Low Energy-Only System-On-Chip with Support for Wireless Charging.pdf new file mode 100644 index 0000000..aaf6e97 Binary files /dev/null and b/Anaren_uart_example/Doc/BCM20737 - Single-Chip Bluetooth Low Energy-Only System-On-Chip with Support for Wireless Charging.pdf differ diff --git a/Anaren_uart_example/XRA1201.c b/Anaren_uart_example/XRA1201.c new file mode 100644 index 0000000..b672b47 --- /dev/null +++ b/Anaren_uart_example/XRA1201.c @@ -0,0 +1,2 @@ +#include "XRA1201.h" + diff --git a/Anaren_uart_example/XRA1201.h b/Anaren_uart_example/XRA1201.h new file mode 100644 index 0000000..e7db08a --- /dev/null +++ b/Anaren_uart_example/XRA1201.h @@ -0,0 +1,8 @@ +#ifndef XRA1201_H +#define XRA1201_H +#include +#include +#include +#include + +#endif //XRA1201_H diff --git a/Anaren_uart_example/makefile.mk b/Anaren_uart_example/makefile.mk index 7a3617b..3bd3082 100644 --- a/Anaren_uart_example/makefile.mk +++ b/Anaren_uart_example/makefile.mk @@ -11,7 +11,7 @@ ######################################################################## # Application sources. ######################################################################## -APP_SRC = uart_example.c utils.c +APP_SRC = uart_example.c utils.c XRA1201.c ######################################################################## ################ DO NOT MODIFY FILE BELOW THIS LINE #################### diff --git a/Anaren_uart_example/uart_example.c b/Anaren_uart_example/uart_example.c index 31a0cd7..bdf77a5 100644 --- a/Anaren_uart_example/uart_example.c +++ b/Anaren_uart_example/uart_example.c @@ -43,6 +43,7 @@ const BYTE RED_LED = GPIO_PIN_P26; const BYTE GREEN_LED = GPIO_PIN_P27; const BYTE BLUE_LED = GPIO_PIN_P28; const BYTE BUZZER = GPIO_PIN_P14; +const BYTE IOEXPAND_INT = GPIO_PIN_2; BLE_PROFILE_CFG puart_control_cfg = {0}; // Please note that all UUIDs need to be reversed when publishing in the database @@ -73,6 +74,8 @@ BLE_PROFILE_CFG puart_control_cfg = {0}; static void app(void); static void timer_cb(UINT32 value); static void fine_timer_cb(UINT32 value); +static UINT8* showActivity(UINT8 *buffer); +static void ioexpand_int_handler(void *data, UINT8 pin); /****************************************************** * Variables Definitions @@ -97,8 +100,8 @@ const UINT8 gatt_database[] = CHARACTERISTIC_UUID128_WRITABLE(0x0015, 0x0016, SERVICE_1_CHARACTERISTIC_3_UUID, LEGATTDB_CHAR_PROP_READ|LEGATTDB_CHAR_PROP_WRITE|LEGATTDB_CHAR_PROP_NOTIFY, - LEGATTDB_PERM_READABLE|LEGATTDB_PERM_WRITABLE|LEGATTDB_PERM_WRITE_REQ, 16), - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + LEGATTDB_PERM_READABLE|LEGATTDB_PERM_WRITABLE|LEGATTDB_PERM_WRITE_REQ, 18), + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, CHAR_DESCRIPTOR_UUID16_WRITABLE(0x17, UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION, @@ -132,7 +135,8 @@ const UINT8 gatt_database[] = BD_ADDR ble_device_addr = {0}; uint8_t run = 1; -uint16_t raw_temp = 0; +uint8_t temp = 0.0; +UINT8 activityBuffer[4] = {'.',' ',' ',0}; char recvBuffer[20]; BYTE numConnectedClients = 0; @@ -142,13 +146,13 @@ BYTE numConnectedClients = 0; static void serial_rxCb(void *unused) { UINT8 character = 0; - static uint8_t i = 0; - + uint8_t i = 0; while (puart_rxFifoNotEmpty() && puart_read(&character)) { puart_write(character); recvBuffer[i++ % 20] = character; + bleapputils_delayUs(500); //Needed to let some time to the uart to receive the data } recvBuffer[i] = '\0'; @@ -158,12 +162,14 @@ static void serial_rxCb(void *unused) P_UART_INT_ENABLE |= P_UART_ISR_RX_AFF_MASK; if(memcmp(recvBuffer,"stop", 4) == 0) - run = 0, i = 0; + run = 0; else if(memcmp(recvBuffer,"start", 4) == 0) - run = 1, i = 0; + run = 1; +} - if(strlen(recvBuffer) > 3) - i = 0; +static void ioexpand_int_handler(void *data, UINT8 pin) +{ + puart_print("IO int\n"); } static void ble_link_up(void) @@ -276,6 +282,30 @@ UINT32 uart_device_lpm_queriable(LowPowerModePollType type, UINT32 context) return 0; } +// Makes the litle dot move at the end of the temperature string. +UINT8* showActivity(UINT8 *buffer) +{ + if(buffer[0] == '.') + { + buffer[0] = ' '; + buffer[1] = '.'; + buffer[2] = ' '; + } + else if(buffer[1] == '.') + { + buffer[0] = ' '; + buffer[1] = ' '; + buffer[2] = '.'; + } + else + { + buffer[0] = '.'; + buffer[1] = ' '; + buffer[2] = ' '; + } + return buffer; +} + void app(void) { devlpm_init(); @@ -303,9 +333,11 @@ void app(void) bleprofile_Discoverable(HIGH_UNDIRECTED_DISCOVERABLE, ble_device_addr); - gpio_configurePin(PIN2PORT(RED_LED), PIN2PIN(RED_LED), GPIO_OUTPUT_ENABLE ,0); - gpio_configurePin(PIN2PORT(GREEN_LED), PIN2PIN(GREEN_LED), GPIO_OUTPUT_ENABLE ,0); - gpio_configurePin(PIN2PORT(BLUE_LED), PIN2PIN(BLUE_LED), GPIO_OUTPUT_ENABLE ,0); + gpio_configurePin(PIN2PORT(RED_LED), PIN2PIN(RED_LED), GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_LOW); + gpio_configurePin(PIN2PORT(GREEN_LED), PIN2PIN(GREEN_LED), GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_LOW); + gpio_configurePin(PIN2PORT(BLUE_LED), PIN2PIN(BLUE_LED), GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_LOW); + gpio_configurePin(PIN2PORT(IOEXPAND_INT), PIN2PIN(IOEXPAND_INT), GPIO_INPUT_ENABLE | GPIO_PULL_UP | GPIO_EN_INT_FALLING_EDGE, GPIO_PIN_INPUT_HIGH); + gpio_registerForInterrupt(NULL, ioexpand_int_handler, NULL); //Buzzer config aclk_configure(512000, ACLK1, ACLK_FREQ_24_MHZ); @@ -332,9 +364,8 @@ void timer_cb(UINT32 value) //I2C test uint8_t reg = 0xFE; uint8_t ManuID[2]; + uint16_t raw_temp = 0; - i2cm_init(); - i2cm_setSpeed(I2CM_SPEED_400KHZ); if(i2cm_comboRead(ManuID, 2, ®, 1, 0x40 << 1) == I2CM_SUCCESS) { puart_print("I2C comboRead success\n"); @@ -343,7 +374,8 @@ void timer_cb(UINT32 value) reg = 0x01; i2cm_comboRead(ManuID, 2, ®, 1, 0x40 << 1); raw_temp = (ManuID[0] << 6) + (ManuID[1] >> 2); - puart_printf("Raw temp : 0x%02X%02X -> %u, %u\n", ManuID[0], ManuID[1], raw_temp, raw_temp / 32); + temp = raw_temp / 32; + puart_printf("Raw temp : 0x%02X%02X -> %u, %u\n", ManuID[0], ManuID[1], raw_temp, temp); } else puart_print("I2C comboRead failure\n"); @@ -360,8 +392,8 @@ void fine_timer_cb(UINT32 value) { BLEPROFILE_DB_PDU db_pdu; - UINT8 buffer[15]; - sprintf((char*)buffer,"temp : %u", raw_temp); + UINT8 buffer[18]; + sprintf((char*)buffer,"temp : %u C%s", temp, showActivity(activityBuffer)); puart_printf("%s\nrecvBuffer : #%s#\n",buffer, recvBuffer);