Skip to content
Snippets Groups Projects
Commit f81900ab authored by Isabel Morales's avatar Isabel Morales
Browse files

i2c working at 100kHz

parent 25b19783
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,14 @@
* @file i2c.h
* @brief I2C Module header
*
* Proyecto Smart Watch - UART
* Proyecto Smart Watch - I2C
* I2C module
*
* This module is used to configure the
* I2C module of the MSP432P401R for master mode operation at 100kbps
*
* EUSCI_B0 module of the MSP432P401R for I2C master mode operation at 100kbps
*
* i2c.h
* Module that allows the master mode configuration of the I2C of the MSP432P401R
* Module that allows EUSCI_B0 master mode configuration of the I2C of the MSP432P401R
*
* @authors Leonardo Martínez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
......@@ -18,53 +17,45 @@
*/
/**
* I2C bus parameters
*/
#define SLAVE_MAX32664_W 0XAA // MAX32664 write address (max rate 3400 Kbps)
#define SLAVE_MAX32664_R 0XAB // MAX32664 read address (max rate 3400 Kbps)
/**
* I2C master parametes
*/
#define MASTER_MSP432 0X0
#define MASTER_TX 0X1
#define MASTER_RX 0X2
#define MASTER_ACK 0X3
/**
* I2C variables data
* Constants shared with other modules
*/
//uint16_t send[I2C_DATA]
//uint16_t get[I2C_DATA] = {0x00, 0x00, 0x00}; //HR, SP02, IR
#define SCL (0X0007)
#define SDA (0X0006)
#define BYTE_COUNTER 2 //Initial value for counter
#ifndef INCLUDE_I2C_H_
#define INCLUDE_I2C_H_
/**
* @brief Initializes I2C module
* SMCLK: 12MHz (HFXTCLK - Divider = 4)
* 100kbps
*/
void initI2C(void);
void initializeI2C(void);
/**
* @brief Sets callback function to be added from this module to the function queue
* @param void* callback_function: function to be called when a new message is available
* @brief Starts transmission of a generic write command
* @param int slave_address: Slave address to communicate with master
*
*/
void setI2CCallbackFunction(void *callback_function);
void I2CTxOperation(int slave_address);
/**
* @brief Sends data using I2C module
* @param char* buffer_pointer: auxiliary buffer pointer which contains data to be send
* @brief Starts reception of a generic read command
* @param int slave_address: Slave address to communicate with master
*
*/
void I2CSend(char* buffer_pointer);
void I2CRxOperation(int slave_address);
/**
* @brief Gets data using I2C module
* @param char* buffer_pointer: auxiliary buffer pointer which points to the address to use for get data
* @brief Sets the I2C pointer to a
* @param char* i2c_pointer: pointer to be set to 1 which points i2c queue address array for slave data.
*
*/
void I2CGet(char* buffer_pointer);
void setI2CPointer(int* i2c_pointer_rx);
#endif /* INCLUDE_I2C_H_ */
/**
* @file sen_15219.h
* @brief SEN_15219 Module header
*
* Proyecto Smart Watch - UART
* SEN_15219 module
*
* This module is used to send/get I2C data from
* SEN_15219 module to the MSP432P401R for photopletysmography dereived parameters.
*
*
* sen_15219.h
* Module that allows a photopletysmograph configuration for the SMART WATCH aplication.
*
* @authors Leonardo Martnez <leonardo.martinez.hornak@fing.edu.uy>, Isabel Morales <imorales@fing.edu.uy>
* @version 1.0
* @date May 21, 2021
*/
/**
* I2C SEN Address
*/
#define SLAVE_MAX32664_W 0XAA // MAX32664 write address (max rate 3400 Kbps)
#define SLAVE_MAX32664_R 0XAB // MAX32664 read address (max rate 3400 Kbps)
/**
* I2C bus parameters
*/
#define DATA_3 3 // I2C transaction frame
#define DATA_5 5 // I2C transaction frame
#define MFIO (0X0004)
#define RSTN (0X0005)
#ifndef INCLUDE_SEN_15219_H_
#define INCLUDE_SEN_15219_H_
/**
* @brief Sets callback function to be added from this module to the function queue
* @param void* callback_function: function to be called when a new message is available
*
*/
void initializeSen15219(void);
void initializaModeSen15219(int mode);
void configureSen15219(void);
#endif /* INCLUDE_SEN_15219_H_ */
......@@ -3,6 +3,7 @@
#include "user_interface.h"
#include "gpio.h"
#include "timing_logic.h"
#include "i2c.h"
void (*task)();
......@@ -15,9 +16,12 @@ void main(void)
initFunctionQueue();
initializeGPIOModule();
initializeUserInterface();
initializeTimingLogic();
//initializeTimingLogic();
configureClockSystem();
initializeI2C();
__enable_irq();
while(1)
{
if(!functionQueueIsEmpty())
......@@ -29,6 +33,9 @@ void main(void)
{
__low_power_mode_0();
}
I2CTxOperation(0xAA);
}
}
......
/*
* i2c.c
*
* Created on: May 22, 2021
* Author: ANGELICA
*/
#include <msp.h>
#include "i2c.h"
#include "fifo_queue.h"
#include "common.h"
static int counter = BYTE_COUNTER;
static int data;
int i=0;
void initializeI2C(void)
{
//Green led output for testing
//TODO clear green led when merging to master
P2OUT &= ~BIT1;
P2DIR |= BIT1;
//Configure I2C pins P1.7 - SCL / P1.6 - SDA glithc_filter 50ns?
P1SEL0 |= SCL;
P1SEL1 &= ~SCL;
P1SEL0 |= SDA;
P1SEL1 &= ~SDA;
//Configure USCI_B0 as I2C
//Reset EUSCI_B0 while being configured
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SWRST;
//MST Master mode enable
//MODE 3 i2c
//Synchronous mode enabled
//UCSSEL 2 SMCLK (12MHz)
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_MST |
EUSCI_B_CTLW0_MODE_3 |EUSCI_B_CTLW0_SYNC |
EUSCI_B_CTLW0_SSEL__SMCLK;
// Disabled low timeout clock counter
// Send NACK before the STOP condition as a master receiver
// ASTP enabled. Automatically generates a STOP condition
//when (UCBxTBCNT) counter value is reached - BCNTIGF flag
EUSCI_B0->CTLW1 |= EUSCI_B_CTLW1_ASTP_2;
//TODO Increase to 400kHz
// SMCLK / BRW = 100kHz - desired baudrate (12MHz/100kHz)=120
EUSCI_B0->BRW = 120;
// Byte counter threshold register. Sets the number of data bytes
// after which the UCSTPIFG EUSCI_B_IFG_STPIFG
//(or automatic stop) should occur. STPx must be different from 0
EUSCI_B0->TBCNT = counter;
//Turn on the module
EUSCI_B0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST;
//Enable RX interrupts:receive, NACK and byte counter interrupt
EUSCI_B0->IE |= EUSCI_B_IE_RXIE | EUSCI_B_IE_NACKIE | EUSCI_B_IE_BCNTIE ;
//Enable TX interrupts: transmit and stop interrupt
EUSCI_B0->IE |= EUSCI_B_IE_TXIE;
NVIC_SetPriority(EUSCIB0_IRQn,0);
NVIC_EnableIRQ(EUSCIB0_IRQn);
}
void I2CRxOperation(char* buffer_pointer)
{
//UCTR Receiver mode
EUSCI_B0->CTLW0 &= ~EUSCI_B_CTLW0_TR;
}
void I2CTxOperation(int slave_address)
{
char value;
i = 0;
//UCTR Transmiter mode
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TR;
// SLAVE address
EUSCI_B0->I2CSA = slave_address;
//STOP condition sent reassured
//TODO ASSERT????
while (EUSCI_B0->CTLW0 & EUSCI_B_CTLW0_TXSTP);
// I2C START condition
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TXSTT;
P2OUT &= ~BIT1;
}
void EUSCIB0_IRQHandler(void)
{
//Writing the UCTXBUF clears UCTXIFG0
if (EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0)
{
if(i==0){
EUSCI_B0->TXBUF = 0x00;
i++;
}
else if(i==1){
EUSCI_B0->TXBUF = 0x00;
i++;
}
else{
EUSCI_B0->TXBUF = 0x00;
i++;
}
P2OUT |= BIT1;
__low_power_mode_off_on_exit();
}
}
#include <msp.h>
#include "sen_15219.h"
#include "i2c.h"
#include "fifo_function_queue.h"
#include "timing_logic.h"
//Callback function for queue
//void (*sen15219_callback)();
void initializeSen15219(void)
{
//Set P6 as out put
P6OUT &= ~MFIO;
P6OUT &= ~RSTN;
P6DIR |= MFIO | RSTN;
P6SEL1 |= MFIO | RSTN;
P6SEL0 = 0;
//initializeTimingLogic();
//initializei2c();
//Slave_WriteAddress(1 byte)|Command_Family(1 byte)|Command_Index(1byte)|Value(multiple bytes)
}
void initializaModeSen15219(int mode)
{
if(mode==0)
{
//Aplication mode
P6OUT |= MFIO; //Must be pulled HIGH
P1OUT &= ~RSTN; //Reset LOW for 10ms
__delay_cycles(10);
P1OUT |= RSTN; //Reset HIGH for 50ms
__delay_cycles(100);
P1REN |= MFIO; //Enable interrupt
}else
{
//Bootloader mode
}
}
void configureSen15219(void)
{
}
void setSen15219Function(void *callback_function)
{
}
......@@ -20,8 +20,8 @@ void configureTimer(void)
//TACCR = 1mS / (1 / 12MHz) - 1. 1 is substracted because the flag is triggered one cycle later
TIMER_A0 -> CCR[0] = 11999;
__NVIC_SetPriority(TA0_0_IRQn,0);
__NVIC_EnableIRQ(TA0_0_IRQn);
NVIC_SetPriority(TA0_0_IRQn,0);
NVIC_EnableIRQ(TA0_0_IRQn);
}
unsigned int getCurrentTime(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment