Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2c in msp430fg4618 experimenter's board.

Status
Not open for further replies.

iVenky

Advanced Member level 2
Joined
Jul 11, 2011
Messages
584
Helped
37
Reputation
76
Reaction score
35
Trophy points
1,318
Location
College Station, Texas
Activity points
6,124
I am trying to interface digital compass with msp430fg4618. For that I need to use I2c. I tried the sample code but I didn't get the CLK (Clock)signal. I don't know what's wrong with the code. If you know any link regarding i2c using msp430fg4618 please post it. I know about I2c so no need to post any link regarding I2c. I just don't know to do that with msp430fg4618( experimenter's board.)

Thanks in advance.
 

Hello!

What do you mean by "I tried the sample code"? Which sample code was it?
What do you mean by "I didn't get the clock"? Usually a sensor is slave, the MCU is master (In all the
sensors I played with, it was the case. So id you wait for the clock, it will never come. The clock is
the responsibility of the master.

Dora.
 
  • Like
Reactions: iVenky

    iVenky

    Points: 2
    Helpful Answer Positive Rating
Hello!

What do you mean by "I tried the sample code"? Which sample code was it?
What do you mean by "I didn't get the clock"? Usually a sensor is slave, the MCU is master (In all the
sensors I played with, it was the case. So id you wait for the clock, it will never come. The clock is
the responsibility of the master.

Dora.

Do you have the code for i2c using msp? I would be really happy if you provide me some kind of a link.


There is an inbuilt thermometer in the msp430fg4618/f2013 experimenter's board. I tried the following code but I didn't get anything (except that it displays Hello by default).
Here's the main() of the code that I wrote. I have left out the definitions those additional functions (like DisplayHello() etc. )because I am very sure that there is no problem in those functions as they worked perfectly with other codes.



Code:
void main (void)
{
volatile uint16_t i; // Loop counter to stabilize FLL+
int16_t Temperature; // Value received over I2C
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
FLL_CTL0 = XCAP14PF; // 14pF load caps; 1MHz default
do { // Wait until FLL has locked
for (i = 0x2700; i > 0; --i) { // One loop should be enough
} // Delay for FLL+ to lock

//IFG1_bit.OFIFG = 0; // Attempt to clear osc fault flag

IFG1&=~OFIFG;
} while (IFG1 & OFIFG != 0); // Repeat if not yet clear
PortsInit (); // Initialize ports
LCDInit (); // Initialize SBLCDA4
DisplayHello (); // Display HELLO on LCD

P3SEL = BIT1 | BIT2; // Route pins to USCI_B for I2C

// 7-bit addresses (default), single master , master mode , I2C , synch
UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC;
// Clock from SMCLK , receiver (default), hold in reset

UCB0CTL1 = UCSSEL_2| UCSWRST;
UCB0BR1 = 0; // Upper byte of divider word
UCB0BR0 = 11; // Clock = SMCLK / 10 = 100 KHz
UCB0I2COA = 0; // Ignore genl call; own address = 0

UCB0I2CSA = SLAVE_ADDRESS; // Slave to be addressed
UCB0CTL1 &= ~UCSWRST; // Release from reset

// Set up basic timer for interrupts at 2Hz (500ms)
BTCTL = BTHOLD | BT_ADLY_500; // Hold , period = 500ms from ACLK
BTCNT2 = 0; // Clear counter
BTCTL &= ~BTHOLD; // Start basic timer
IE2|= BTIE;
for (;;) { // Transfers triggered by BT
__low_power_mode_3 (); // Wait for BT (needs only ACLK)

P5OUT= BIT1;
UCB0CTL1 |= UCTXSTT; // Send Start and slave address
while (( UCB0CTL1 & UCTXSTT) != 0) {
} // Wait for address to be sent
if (( UCB0STAT & UCNACKIFG) != 0) { // Address NOT acknowledged?
UCB0CTL1 |= UCTXSTP; // Send Stop condition and finish
} else { // Address acknowledged: receive
while (IFG2 & UCB0RXIFG == 0) {
} // Wait for first byte
Temperature = UCB0RXBUF << 8; // MSB of temperature
UCB0CTL1 |= UCTXSTP; // Send Stop condition after byte
while (IFG2 & UCB0RXIFG == 0) {
} // Wait for second byte
Temperature |= UCB0RXBUF; // LSB of temperature
DisplayCentiCels (Temperature); // Display temp to 0.01oC
}
P5OUT &= ~BIT1; // Show end of activity
}
}


#pragma vector = BASICTIMER_VECTOR
__interrupt void BASICTIMER_ISR (void) // Acknowledged automatically
{
__low_power_mode_off_on_exit(); // Return to start new I2C message
}


I connected the the pin 1 and 2 and also pins 3 and 4 of H1 in the experimenter's board for inter processor communication. According to the datasheet I should be getting the clock from the pin 4 of H1 but I didn't get anything.

I would be really obliged if you could provide me some code or link because I am in a desperate situation.
 
Last edited:

Hello!

Your code is not indented and therefore difficult to read.
So basically you want to read on MSP430 from the other?
You don't use the compass this time, do you?
Now if you want to read the temperature from the other chip using I2C,
I suppose you already wrote the slave code that goes into the other
chip, right?
By the way, you don't necessarily need interrupts to use I2C if it's
just to get data from a sensor.

Dora.
 
  • Like
Reactions: iVenky

    iVenky

    Points: 2
    Helpful Answer Positive Rating
Hello!

Your code is not indented and therefore difficult to read.
So basically you want to read on MSP430 from the other?
You don't use the compass this time, do you?
Now if you want to read the temperature from the other chip using I2C,
I suppose you already wrote the slave code that goes into the other
chip, right?
By the way, you don't necessarily need interrupts to use I2C if it's
just to get data from a sensor.

Dora.



My main aim is to interface digital compass with msp430fg4618 only. I wrote this code because msp430fg4618 basis guide has some instructions regarding this thermometer. It didn't say that I should burn the code in the slave. Here slave is the thermometer which is inbuilt in the msp430fg4618/f2013 experimenter's board.

Okay if you know how to interface msp430fg4618 with the digital compass (which is my main aim and not thermometer) then please help me out. I would be really happy if you help me. The address of digital compass for reading I believe is 0x42. If you know any links or if you have the code for some other interfacing that you have done please share it with me.

Thanks in advance.



Here's the code with indentation-

Code:
void main (void)
{
       volatile uint16_t i; // Loop counter to stabilize FLL+
       int16_t Temperature; // Value received over I2C
       WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
       FLL_CTL0 = XCAP14PF; // 14pF load caps; 1MHz default
    do { // Wait until FLL has locked
           for (i = 0x2700; i > 0; --i) { // One loop should be enough
         } // Delay for FLL+ to lock

     IFG1&=~OFIFG;
} while (IFG1 & OFIFG != 0); // Repeat if not yet clear
 
//I have defined these functions and I haven't included them here. They are right and there is no error with those functions as those functions worked with other codes.

PortsInit (); // Initialize ports
LCDInit (); // Initialize SBLCDA4
DisplayHello (); // Display HELLO on LCD


   P3SEL = BIT1 | BIT2; // Route pins to USCI_B for I2C
   // 7-bit addresses (default), single master , master mode , I2C , synch
   UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC;
   // Clock from SMCLK , receiver (default), hold in reset
   UCB0CTL1 = UCSSEL_2| UCSWRST;
   UCB0BR1 = 0; // Upper byte of divider word
   UCB0BR0 = 11; // Clock = SMCLK / 10 = 100 KHz
   UCB0I2COA = 0; // Ignore genl call; own address = 0
   UCB0I2CSA = SLAVE_ADDRESS; // Slave to be addressed
   UCB0CTL1 &= ~UCSWRST; // Release from reset

   // Set up basic timer for interrupts at 2Hz (500ms)
   BTCTL = BTHOLD | BT_ADLY_500; // Hold , period = 500ms from ACLK
   BTCNT2 = 0; // Clear counter
   BTCTL &= ~BTHOLD; // Start basic timer
   IE2|= BTIE;
   for (;;) { // Transfers triggered by BT
   __low_power_mode_3 (); // Wait for BT (needs only ACLK)

   P5OUT= BIT1; 
   UCB0CTL1 |= UCTXSTT; // Send Start and slave address
     while (( UCB0CTL1 & UCTXSTT) != 0) {
       } // Wait for address to be sent
       if (( UCB0STAT & UCNACKIFG) != 0) { // Address NOT acknowledged?
           UCB0CTL1 |= UCTXSTP; // Send Stop condition and finish
         } 
       else { // Address acknowledged: receive 
           while (IFG2 & UCB0RXIFG == 0) {
              } // Wait for first byte
          Temperature = UCB0RXBUF << 8; // MSB of temperature
          UCB0CTL1 |= UCTXSTP; // Send Stop condition after byte
          while (IFG2 & UCB0RXIFG == 0) {
          } // Wait for second byte
             Temperature |= UCB0RXBUF; // LSB of temperature
            DisplayCentiCels (Temperature); // This displays the temperature and there is no problem with this function. 

}

      P5OUT &= ~BIT1; // Show end of activity
}
}


#pragma vector = BASICTIMER_VECTOR
__interrupt void BASICTIMER_ISR (void) // Acknowledged automatically
{
__low_power_mode_off_on_exit(); // Return to start new I2C message
}
 
Last edited:

Hello!

If you don't say what compass you are going to use, I guess nobody can help you.
Beside this, there is some sample code explaining how to use I2C from MSP430 to
a slave, that's probably what you got. Why not trying to do with what you have?
I used TI's code, I just removed interrupt stuff because it's not mandatory for a
small utility just reading 2 bytes, and that's it.
Now what you have to adjust from TI's code is:
- The device address. CAREFUL: it looks like everybody uses its own standard
for the chip address. So if the address is 0x42, knowing that these are bits 7
to 1, it might be 0x84 as well. So depending on how the chip maker and also TI
interpret these 7 bits, you may want to try 0x42 but also 0x84 and 0x21.
- The number of address bytes (inside of the chip). That's probably 1. If you take
code from an EEPROM for instance, it can be 2 or 3 bytes, so just make sure the
number of address bytes you send is compliant with the chip you use.
- Verify the specs regarding the ack / noack policies. I'm not sure, but I have the
impression that nothing is standard, so I verify each time with the chip specs.

That's about it.

Dora.
 

The compass that I am using is HMC6352. Also the I2C address for reading is 0x43 as per the datasheet. The module has pull up resistors so no need to give it externally. I have some doubts-
1) There are many TI sample codes for I2C. Which code are you talking about?
Here's the link for downloading the sample codes. I would be really happy if you download the sample codes for msp430fg461x and tell me which code I should be using.

http://www.ti.com/lsds/ti/microcontroller/16-bit_msp430/msp430_software_landing.page#code

2) I am interfacing msp430fg4618 as master with the digital compass. I burned the code in the mps430fg4618 (master). Should I burn some code in the slave ?(which is digital compass here)
3)How do you verify if your code is correct in I2C because I am not getting any CLK signal with the above code?


If you have any code regarding I2C please post it.

Thanks in advance.
 

Hello!

The code I developed for HMC6352 was based on TI's I2C examples, but I used only
the initialization and then wrote 2 functions (if I remember correctly), one for writing
parameters and one for reading the heading which was coded on 2 bytes I think.
Hint: Look at the specs sheet, load the UCBxI2COA (address), add a UCTXSTP or UCTXSTT
when necessary, add data to UCBxTXBUF or get it from UCBxRXBUF when necessary
and that will be about it.

There is nothing to burn inside of the sensor. I was asking that because I thought you
wanted to test I2C on the 4618 board, the one that has 2 chips, one 4618 and one 2x
(I don't remember its type). I thought you wanted to read the 2x temperature from the
4628 by I2C in which case you have to program the 2x. Now you are reading a sensor,
so there is nothing to program in it.
Now if you have no clock, you obviously forgot something. Maybe you forgot the PxSEL
If you initialize for I2C, both signals should be high as long as you send nothing.

Instead of waiting that I write code for you did you try something by yourself?
If you don't like to read the docs (I don't either), just look at the timings (they are in
the honeywell document), that's more than enough. As for I2C itself, you were saying
in your firs post: "I know about I2c so no need to post any link regarding I2c."
so I'm sure you can solve your problem easily.

Dora.
 

The problem is that there are many ti codes used for I2c. Most of the codes are for communication between two msp. I found one code that might be for reading data from the slave. Just tell me if this correct and also the changes that I have to make.

I see that this code includes for reception too. Just tell me which lines I should delete so that there is no reception involved. Also will this code be correct for reading data from the compass (if I change the address)?

Thanks in advance.


Code:
//******************************************************************************
//   MSP430xG461x Demo - USCI_B0 I2C Master Interface to PCF8574, Read/Write
//
//   Description: I2C communication with a PCF8574 in read and write mode is
//   demonstrated. PCF8574 port P is configured with P0-P3 input, P4-P7. Read
//   P0-P3 input data is written back to Port P4-P7. This example uses the
//   RX ISR and generates an I2C restart condition while switching from
//   master receiver to master transmitter.
//   ACLK = 32kHz, MCLK = SMCLK = TACLK = BRCLK = 1MHz
//
//                                MSP430xG461x
//                              -----------------
//                  /|\ /|\ /|\|              XIN|-
//                  10k 10k  | |                 | 32kHz
//       PCF8574     |   |   --|RST          XOUT|-
//       ---------   |   |     |                 |
//  --->|P0    SDA|<-|---+---->|P3.1/UCB0SDA     |
//  --->|P1       |  |         |                 |
//  --->|P2       |  |         |                 |
//  --->|P3    SCL|<-+---------|P3.2/UCB0SCL     |
//  <---|P4       |            |                 |
//  <---|P5       |            |                 |
//  <---|P6       |            |                 |
//  <---|P7       |            |                 |
//   +--|A0,A1,A2 |            |                 |
//   |  |         |            |                 |
//  \|/
//
//   Andreas Dannenberg/ M. Mitchell
//   Texas Instruments Inc.
//   October 2006
//   Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include "msp430xG46x.h"

unsigned char i=0;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
  P3SEL |= 0x06;                            // Assign I2C pins to USCI_B0
  UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  UCB0BR0 = 11;                             // fSCL = SMCLK/11 = 95.3kHz
  UCB0BR1 = 0;
  UCB0I2CSA = 0x20;                         // Set slave address
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  IE2 |= UCB0RXIE;                          // Enable RX interrupt
  TACCTL0 = CCIE;                           // TACCR0 interrupt enabled
  TACTL = TASSEL_2 + MC_2;                  // SMCLK, contmode

  while (1)
  {
    __bis_SR_register(CPUOFF + GIE);        // CPU off, interrupts enabled
    UCB0CTL1 &= ~UCTR;                      // I2C RX
    UCB0CTL1 |= UCTXSTT;                    // I2C start condition
    while (UCB0CTL1 & UCTXSTT);             // Loop until I2C STT is sent
    UCB0CTL1 |= UCTR+UCTXSTT;               // I2C TX, start condition
    __bis_SR_register(CPUOFF + GIE);        // CPU off, interrupts enabled
    while (UCB0CTL1 & UCTXSTT);             // Loop until I2C STT is sent
    UCB0CTL1 |= UCTXSTP;                    // I2C stop condition after 1st TX
  }
}

#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Exit LPM0
}

// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
  UCB0TXBUF = (UCB0RXBUF << 4) | 0x0f;      // Move RX data to TX
  __bic_SR_register_on_exit(CPUOFF);        // Exit LPM0
}
 

Hello!

I see that this code includes for reception too. Just tell me which lines I should delete so that there is no reception involved.
Also will this code be correct for reading data from the compass (if I change the address)?

1. If you can see that there is reception, then why not deleting the lines that involve reception?

2. If you delete reception parts, how are you going to receive bytes from the compass?

3. I don't know if this code works. I mean, I'm sure it does because it's TI's code. But
I'm not sure it will work with your compass for reasons explained earlier. Why not trying
it and trying to modify until it works?
Hint: you may want to read the chip's documentation. And you may want to hook a scope
on SDA / SCL to watch what happens. And if you don't like docs, just read the timings
available in the compass docs, and also MSP's I2C state diagrams.

Dora.
 
  • Like
Reactions: iVenky

    iVenky

    Points: 2
    Helpful Answer Positive Rating
Sorry, I mean I wish to delete the transmission part and not the reception part. The thing is that I am not familiar with the registers in the msp430. That's the reason why I asked you to specify the places that I should delete so that there is no transmission. Just tell me those lines. The rest I will do.

Thanks in advance.

---------- Post added at 09:41 ---------- Previous post was at 09:39 ----------

Just tell me this- Is this the code for reading data from a device because I saw many ti sample codes involving two msp430 and I got confused.
 

Please. I am in desperate situation. Help me with this thing.

---------- Post added at 11:30 ---------- Previous post was at 11:27 ----------

One doubt- If I just burn that sample code, I am not getting any clock signal in that pin. I haven't connected the digital compass to the microcontroller. I just want to check if I get the clock. Will we get the clock if we don't connect the digital compass?
 

I checked the clock with the oscilloscope. I am getting only 8 hz. I even changed the division count in that register but I still get 8 hz only. What's the problem?

Thanks in advance.
 

I have similar issues with the MSP430G2553 and have not solved it. Make sure you are measuring the right pin for the clock. 8 Hz signal sounds like a data line measurement. Also, try using an external clock on ACLK and see if a clock signal is seen on the I2C.
 

I checked the clock with the oscilloscope. I am getting only 8 hz. I even changed the division count in that register but I still get 8 hz only. What's the problem?

Thanks in advance.

Hi iVenky, I'm Thang, from VietNam
I'm on your past problem. If you're finished you project, could you give some answers.

1/ Will we get the clock if we don't connect the digital compass?
2/ How you fix the problem of changing divide number but Clk does not change corresponding?

Thank you so much for this.
 

Hello!

1/ Will we get the clock if we don't connect the digital compass?
2/ How you fix the problem of changing divide number but Clk does not change corresponding?

1. Your digital compass is slave. The clock is the responsibility of the master (i.e. your chip).
If you don't get the clock, it's simply because you don't generate it.

2. Sorry, I don't understand your question.

Dora.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top