HEllo,
i am currently trying to get a external FRAM running via I2C and my MSP.
First of all i tried to use the Example-Code from appnote "slaa382": Using the USCI I2C Master:
It is workin somehow, but i really do not understand the code which is behind it. I do know how to access my FRAM and i can see the first byte sent is my address, as it is supposed to be. But after my address i do not really understand how to send the right bytes.
So if smoeone really is into the I2C stuff and would like to give me some hnits i would be really glad.
First of all i write my main.c routine for sending and recieving, it is basically the same as the one used by the app note, with some addiotial thnigs in it. As some might have read before hte I2C tends to get stuck on a low SDA line, so is mine so i toggle both lines as GPIOs several times to get rid of this effect. I dont know what exactly is happening there, but i read this solution in another forum and i tried and and it always gets my I2C to work again after it got stuck by some reasons i do not really understand neither :)
#include "msp430f2274.h"
#include "TI_USCI_I2C_master.h"
unsigned char timercounter;
unsigned char array[40] = { 0x0, 0x0, 0x7, 0x6, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb };
unsigned char store[40] = { 13, 13, 13, 13, 13, 13, 13, 0, 0, 0};
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
// I2C wieder in Tritt bekommen
P3SEL &= ~SDA_PIN;
P3SEL &= ~SCL_PIN;
P3OUT &= ~SCL_PIN;
P3OUT &= ~SDA_PIN;
P3DIR |= SCL_PIN;
P3DIR &= ~SDA_PIN;
int temp;
for(temp = 0; temp<1000; temp++){
P3OUT ^= SDA_PIN;
P3OUT ^= SCL_PIN;
}
_EINT();
TI_USCI_I2C_transmitinit(0xA1,0x14); // init transmitting with USCI
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
if ( TI_USCI_I2C_slave_present(0x50) ) // slave address may differ from
{ // initialization
TI_USCI_I2C_transmitinit(0x50,0x14); // init transmitting with
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
TI_USCI_I2C_transmit(4,array); // start transmitting
TI_USCI_I2C_receiveinit(0x50,0x14); // init receiving with USCI
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
TI_USCI_I2C_receive(4,store);
while ( TI_USCI_I2C_notready() ); // wait for bus to be free
}
//LPM3;
}
So i thought i simply write something into my FRAM, at the addresses beginngin from 0x00, and afterwards i could read them out with the TI_USCI_I2C_receive(4,store); routine.
But as always it isnt working that logically, somehow i wont get the bits i was trying to transmit to these addresses.
Lets do that one by one:
unsigned char array[40] = { 0x0, 0x0, 0x7, 0x6, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb };
TI_USCI_I2C_transmit(4,array); // start transmitting
With this i want to write to the FRAM, the first 2 cars in the array are supposed to be my address internally in the FRAM, so starting from address 0x00 i then write another 2 chars in it, the 0x7 and the 0x6. This by the way i cannot see in the osciloscope, perhaps because i set the wrong breakpoints, but frmo my experience i suppose that is should be sent and be available in the FRAM for later actions.
TI_USCI_I2C_receive(4,store);
With this i try to get out the written memory blocks from before. This part i can clearly seein the osciloscope, but i see the wron bit patterns, it isnt 7 and 6 i am gettnig but somethign different like only 0 or F( all bits high).
I am kind of confused about the routine TI presents, if someone is familiar with it, suppose there are way too many stop conditions in those Interrupt subroutines, that does not really fit my FRAM.
Could it be that i have to write a very own routine for my special fujitsu FRAM or should the I2C be the same for every purpose?
Please feel free to help me, or i am wasting another hours on this communication stuff.
Thanks for tmie and help.
Seb