Part Number: MSP430FR2311
Other Parts Discussed in Thread: MSP430FR2111
Tool/software: Code Composer Studio
Hi there folks,
I'm having a problem with the Software I²C that is found in this guide http://www.ti.com/lit/an/slaa703/slaa703.pdf . When I'm executing on my MSP430FR2311, it enters an ISR trap after calling TIMER_ITERATION() (sometimes it loops and calls this function more than once before entering trap).
I've changed the timers to use the Timer B (since MSP430FR2311 doesn't have the Timer A), and I left the pins untouched (the software I²C uses exactly the pins I need).
My main.c is as below:
#include <stdint.h>
#include <stdbool.h>
#include <msp430.h>
#include "msp430_swi2c_master.h"
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;
__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz
CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked
CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
// default DCOCLKDIV as MCLK and SMCLK source
SWI2C_I2CTransaction myTransaction;
uint8_t myBuffer[1] = {0xFF};
/* Initializing the master */
SWI2C_initI2C();
/* Setting up the transaction */
myTransaction.address = 0x38;
myTransaction.writeBuffer = myBuffer;
myTransaction.numWriteBytes = 1;
if(!SWI2C_performI2CTransaction(&myTransaction))
{
/* Handle Error Code Here */
}
while(1);
}
The part that the code hangs is located in msp430_swi2c_master.c.
/* Loop to read until all bits have been read */
do
{
/* Priming our temporary variable and sending a clock pulse */
temp = (temp << 1);
SWI2C_SCL_HIGH;
TIMER_ITERATION();
/* If the data line is high, recording that */
if (SWI2C_PxIN & SWI2C_SDA)
{
temp += 1;
}
/* Send out another clock cycle and decrement our counter */
bits = (bits - 1);
SWI2C_SCL_LOW;
TIMER_ITERATION();
}
I've tried increasing stack size up to 1000kB (almost the entire RAM), but no success. Also, I've tried to modify the source code for the MSP430FR2111 (found on this guide http://www.ti.com/lit/an/slaa714/slaa714.pdfd) and the result is the same. Is there an additional configuration I'm missing?