Skip to content
Snippets Groups Projects
Commit 04fd0400 authored by Leonardo Martinez Hornak's avatar Leonardo Martinez Hornak
Browse files

Communications code structured

parent f5a8f7e6
No related branches found
No related tags found
No related merge requests found
......@@ -15,5 +15,6 @@
#define REF_VOLTAGE_DIV_BY_ADC_10BITS_RESOLUTION 1.17
#define QUEUE_DIMENSION_UART 20
#define MESSAGE_DIMENSION 20
#endif /* INCLUDE_COMMON_H_ */
......@@ -25,10 +25,9 @@
void initializeCommunications(void);
/**
* @brief Sends a char array
* @param char* buffer_pointer: auxiliary buffer pointer which contains data to be transmitted
* @brief Sends packet using communications interface
*
*/
void sendPacket(char* buffer_pointer);
void sendPacket(void);
#endif /* INCLUDE_COMMUNICATIONS_H_ */
......@@ -3,6 +3,7 @@
#include "user_interface.h"
#include "gpio.h"
#include "body_temperature.h"
#include "communications.h"
void (*task)();
......@@ -15,10 +16,19 @@ void main(void)
volatile int i;
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
//TODO Remove - Crystal configuration
//Basic Clock System Control Register 1 - Turn off XT2 / ACLK Divider = 1
BCSCTL1 = XT2OFF | DIVA_0;
//Basic Clock System Control Register 3 - Use external 32768 Hz crystal for ACLK / capacitance of 12.5pF
BCSCTL3 = LFXT1S_0 | XCAP_3;
initFunctionQueue();
initializeGPIOModule();
initializeUserInterface();
initializeBodyTemperature();
initializeCommunications();
__enable_interrupt();
......
#include "communications.h"
#include "common.h"
#include "user_interface.h"
#include "uart.h"
void processIncomingPacket();
static char rx_buffer_uart[MESSAGE_DIMENSION];
static char tx_buffer_uart[MESSAGE_DIMENSION];
void processIncomingPacket(void);
void initializeCommunications(void)
{
......@@ -9,11 +14,18 @@ void initializeCommunications(void)
setUartCallbackFunction(processIncomingPacket);
}
void sendPacket(char* buffer_pointer){}
void processIncomingPacket()
void sendPacket(void)
{
tx_buffer_uart[0] = 'T';
tx_buffer_uart[1] = '=';
tx_buffer_uart[2] = '\r';
uartTransmit(&tx_buffer_uart[0]);
}
void processIncomingPacket(void)
{
turnOnDebugLED();
}
......
......@@ -16,13 +16,19 @@ void (*message_received_callback)();
void initializeUART()
{
//Keep module in reset while being configured
UCA0CTL1 = UCSWRST;
//UCA0CTL1 = UCSWRST;
EUSCI_A0 -> CTLW0 = EUSCI_A_CTLW0_SWRST;
//Parity disabled, LSB first, 8-bit length, 1 stop bit, asynchronous uart mode
UCA0CTL0 = 0;
//ACLK
EUSCI_A0 -> CTLW0 |= EUSCI_A_CTLW0_UCSSEL_1;
//UCA0CTL0 = 0;
//UCA0CTL1 |= UCSSEL0;
//ACLK source, not dormant mode
UCA0CTL1 |= UCSSEL0;
//Baud Rate = 9600bps, sourced by ACLK @ 32kHZ
//N = frequency of brclk / desired baud rate
......@@ -34,21 +40,33 @@ void initializeUART()
//Second modulation stage = UCBRSx, Oversampling disabled
//UCA0MCTL = UCBRS1 | UCBRS0;
//Configure shared i/o pins
//Tx as output pin
//P1DIR |= TXPIN;
//P1SEL |= TXPIN | RXPIN;
//P1SEL2 |= TXPIN | RXPIN;
//P1.2 Rx as input pin (P1SEL1 = 0, P1SEL0 = 1)
//P1.3 Tx as output pin (P1SEL1 = 0, P1SEL0 = 1)
P1DIR |= BIT3;
P1SEL0 |= BIT2 | BIT3;
//Init queues
initQueue(&head_rx, &tail_rx);
initQueue(&head_tx, &tail_tx);
//Turn on the module
UCA0CTL1 &= ~UCSWRST;
//UCA0CTL1 &= ~UCSWRST;
EUSCI_A0 -> CTLW1 &= ~EUSCI_A_CTLW0_SWRST;
//Enable Interrupts
//UC0IE = UCA0RXIE;
//NVIC_SetPriority(PORT1_IRQn,3);
//NVIC_EnableIRQ(PORT1_IRQn); // Enable PORT1 Interrupt
EUSCI_A0 -> IE |= EUSCI_A_IE_RXIE;
NVIC_SetPriority(EUSCIA0_IRQn,3);
NVIC_EnableIRQ(EUSCIA0_IRQn);
}
void setUartCallbackFunction(void *callback_function)
......@@ -102,35 +120,35 @@ void uartTransmit(char* buffer_pointer)
addToQueue(*(buffer_pointer + i), &head_tx, tx_buffer); //Adding '\r'
}
// UC0IE |= UCA0TXIE;
EUSCI_A0 -> IE |= EUSCI_A_IE_TXIE;
}
/*
#pragma vector=USCIAB0RX_VECTOR
__interrupt void rxUARTInterruptRoutine(void)
void EUSCIA0_IRQHandler(void)
{
if(!queueIsFull(head_rx, tail_rx))
if(EUSCI_A0 -> IFG & EUSCI_A_IFG_RXIFG)
{
addToQueue(UCA0RXBUF, &head_rx, rx_buffer);
if(UCA0RXBUF == '\r')
//ISR - Rx
if(!queueIsFull(head_rx, tail_rx))
{
addToFunctionQueue(message_received_callback);
__low_power_mode_off_on_exit();
}
}
}
addToQueue(EUSCI_A0 -> RXBUF, &head_rx, rx_buffer);
#pragma vector=USCIAB0TX_VECTOR
__interrupt void txUARTInterruptRoutine(void)
{
if(!queueIsEmpty(head_tx, tail_tx))
{
UCA0TXBUF = getFromQueue(&tail_tx, tx_buffer);
if(UCA0RXBUF == '\r')
{
addToFunctionQueue(message_received_callback);
__low_power_mode_off_on_exit();
}
}
}
else
else if(EUSCI_A0 -> IFG & EUSCI_A_IFG_TXIFG)
{
UC0IE &= ~UCA0TXIE;
//ISR - Tx
if(!queueIsEmpty(head_tx, tail_tx))
{
EUSCI_A0 -> TXBUF = getFromQueue(&tail_tx, tx_buffer);
}
else
{
EUSCI_A0 -> IE &= ~EUSCI_A_IE_TXIE;
}
}
}
*/
#include "user_interface.h"
#include "gpio.h"
#include "adc.h"
#include "communications.h"
void turnOnBluetoothModule(void);
......@@ -37,6 +38,7 @@ void turnOnBluetoothModule(void)
{
turnOnLED(LED_BLUE);
runADCConversion();
sendPacket();
prueba = 1;
}
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment