Other Parts Discussed in Thread: TLV320DAC3203,
Hi dear people,
I am sorry to bother you with this boring question, but I am in need of help.
I am trying to work with I2C on a MSP430FR2633, sending as master configurations data to a TLV320DAC3203.
I was looking at everything I could get as examples, but still I am in doubt.
Would you be so kind to check my code snipplet here and guide me in this matter?
Thank you very much in advance!
Gustavo
#include <msp430.h>
#include <stdio.h>
#include "driverlib.h"
#include "eusci_b_i2c.h"
#define MCLK_FREQ_MHZ 2.8224
#define SLAVE_ADDRESS 0x30
configureClocks_to2822400Hz(); // MCLK adjust to 2.8224 MHz
void I2C_masterInit()
{
__bic_SR_register(GIE);
UCB0CTLW0 = UCSWRST; // Enable SW reset
UCB0CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK | UCSYNC; // I2C master mode, SMCLK
UCB0BRW = 28; // fSCL = SMCLK/28 = 2822400/28 = 100800Hz
UCB0I2CSA = SLAVE_ADDRESS; // Slave Address
UCB0CTL1 &= ~UCSWRST; // eUSCI_B in operational state
UCB0CTLW0 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCTXIE; // enable TX-interrupt
UCB0IE |= UCNACKIE;
__bis_SR_register(GIE); // general interrupt enable
}
EUSCI_B_I2C_masterSendMultiByteStart(SLAVE_ADDRESS, regAddress);
EUSCI_B_I2C_masterSendMultiByteNext(SLAVE_ADDRESS, dataValues[j]);
EUSCI_B_I2C_masterSendMultiByteFinish(SLAVE_ADDRESS, dataValues[numDataValues - 1]);
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop the watchdog timer
// Configure I/O pins for I2C
// P1.7-SMCLK
P1SEL |= BIT6 + BIT7;
P1SEL2 |= BIT6 + BIT7;
I2C_masterInit(); // Initialize I2C
// Send I2C start condition
SendMyValues()
// Inside the function SendMyValues() I am using the following functions from
// eusci_b_i2c.c (driver library - Driver for the eusci_b_i2c Module.):
// EUSCI_B_I2C_masterSendMultiByteStart(SLAVE_ADDRESS, regAddress);
// EUSCI_B_I2C_masterSendMultiByteNext(SLAVE_ADDRESS, dataValues[j]);
// EUSCI_B_I2C_masterSendMultiByteFinish(SLAVE_ADDRESS, dataValues[numDataValues - 1]);i2cccccc
free(dataValues); // Free dynamically allocated memory for dataValues
__bis_SR_register(CPUOFF); // Enter low-power mode
}