Problem with I2C Serial EEPROM Driver Using GPIO

Started by StephieU November 29, 2006
I'm working with a DSP (TMS320C2407) and we downloaded some code to
'create' or emulate an i2c bus - however, after downloading the zip files
and trying to build the project it looks like the file

stb.lib is missing

and their are many other compile errors including (see below).  If anyone
has any comments or suggestions - this would be VERY helpful. Thanks!



dspcl se2pd.c -g -v2xx -as -i..\include -i..\..\clib\include
-i..\..\..\..\stb_lib\clib\include
[se2pd.c]
TMS320C2x/C2xx/C5x ANSI C Compiler          Version 7.00
Copyright (c) 1987-1999  Texas Instruments Incorporated 
"..\include\cdemo.h", line 30: [E045] cannot open include file
<regs240x.h>
"..\include\cdemo.h", line 33: [W048] #warn 'Assumed CLKIN--> 7.5 MHz for
TMS320F240x, 5MHz for TMS320F24x'
"..\include\cdemo.h", line 34: [W048] #warn 'Modify if not-->
SYSTEM_INI_PERIOD,PWMDAC_PERIOD,SCSR1_REG_VALUE '
"..\include\cdemo.h", line 61: [E045] cannot open include file <STB.H>
"se2pd.c", line 45: [F001] syntax error at or near symbol 'wdog'
"se2pd.c", line 45: [F108] 'WATCHDOG_DEFAULTS' undefined
"se2pd.c", line 45: [F098] declaration must have type or storage class
   "se2pd.c"   ==> main
   "se2pd.c"   ==> c_int03
"se2pd.c", line 110: [F108] 'EVAIFRB' undefined
   "se2pd.c"   ==> RstInit
"se2pd.c", line 153: [F109] structure or union type required
"se2pd.c", line 154: [F109] structure or union type required
"se2pd.c", line 162: [F108] 'WSGR' undefined
"se2pd.c", line 169: [F108] 'SCSR1' undefined
"se2pd.c", line 172: [F108] 'EVAIMRB' undefined
"se2pd.c", line 173: [F108] 'EVAIFRA' undefined
"se2pd.c", line 174: [F108] 'EVAIFRB' undefined
"se2pd.c", line 175: [F108] 'EVAIFRC' undefined
"se2pd.c", line 176: [F108] 'EVBIFRA' undefined
"se2pd.c", line 177: [F108] 'EVBIFRB' undefined
"se2pd.c", line 178: [F108] 'EVBIFRC' undefined
"se2pd.c", line 185: [F108] 'IMR' undefined
   "se2pd.c"   ==> time_base_init
"se2pd.c", line 226: [F108] 'T2CON' undefined
"se2pd.c", line 227: [F108] 'T2PR' undefined
   "se2pd.c"   ==> phantom

dsplnk se2pd.mak
TMS320C1x/C2x/C2xx/C5x COFF Linker      Version 7.00
Copyright (c) 1987-1999  Texas Instruments Incorporated 

>> se2pd.mak, line 66: can't find input file stb.lib
Build Complete, 21 Errors, 2 Warnings.

StephieU wrote:

> I'm working with a DSP (TMS320C2407) and we downloaded some code to > 'create' or emulate an i2c bus - however, after downloading the zip files > and trying to build the project it looks like the file > > stb.lib is missing > > and their are many other compile errors including (see below). If anyone > has any comments or suggestions - this would be VERY helpful. Thanks! >
Implementing software bit banging I2C master is trivial. Scrap the useless stuff that you have downloaded and implement the I2C from the scratch. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com P.S. Here is the implementation. //====================== File i2c.h =========== #ifndef __I2C_MACHINE_H_INCLUDED #define __I2C_MACHINE_H_INCLUDED /* Interrupt driven I2C master */ /* (c) Abvolt. Ltd */ /* VLV 2005 */ #include "main_defs.h" #include "types.h" // Platform dependent definitions #define SCL_MASK 0x01 #define SDA_MASK 0x02 #define SET_SCL do { DDRB &= ~SCL_MASK; PORTB |= SCL_MASK; } while(0) #define CLR_SCL do { DDRB |= SCL_MASK; PORTB &= ~SCL_MASK; } while(0) #define GET_SCL ((PINB&SCL_MASK) ? 1:0) #define SET_SDA do { DDRB &= ~SDA_MASK; PORTB |= SDA_MASK; } while(0) #define CLR_SDA do { DDRB |= SDA_MASK; PORTB &= ~SDA_MASK; } while(0) #define GET_SDA ((PINB&SDA_MASK) ? 1:0) // I2C system return codes #define I2C_BUSY 0 #define I2C_READY 1 // The low level I2C bus states typedef enum { I2C_BUS_STATE_IDLE, I2C_BUS_STATE_START_0, I2C_BUS_STATE_START_1, I2C_BUS_STATE_TX_0, I2C_BUS_STATE_TX_1, I2C_BUS_STATE_TX_3, I2C_BUS_STATE_TX_4, I2C_BUS_STATE_TX_5, I2C_BUS_STATE_TX_6, I2C_BUS_STATE_TX_7, I2C_BUS_STATE_STOP_1, I2C_BUS_STATE_STOP_2, I2C_BUS_STATE_STOP_3, I2C_BUS_STATE_STOP_4, I2C_BUS_STATE_RX_1, I2C_BUS_STATE_RX_2, I2C_BUS_STATE_RX_3, I2C_BUS_STATE_RX_4, I2C_BUS_STATE_RX_5, I2C_BUS_STATE_RX_6 } I2C_BUS_STATE; typedef struct { I2C_BUS_STATE bus_state; u8 status; u8 address; // Address for communication + R/W bit u8 *buffer; u8 length; // length of the data u8 byte_cntr; // index for data u8 delay_cntr; u8 waitstate_state; u8 byte; u8 byte_bit_cntr; } I2C_STRUCT; void I2C_Init(void); u8 I2C_Status(void); u8 I2C_Action(u8 addr, u8 *data, u8 length); void I2C_BitBanging(void); // To be called from the interrupt with 4x I2C baud rate void I2C_WaitStateCheck(void); // Aux. function #endif //============================== File i2c.c ============= /* Interrupt driven I2C master */ /* (c) Abvolt. Ltd */ /* VLV 2005 */ #include "i2c.h" static volatile I2C_STRUCT i2c; void I2C_Init(void) { SET_SDA; SET_SCL; i2c.bus_state = I2C_BUS_STATE_IDLE; i2c.status = I2C_READY; i2c.address = 0; i2c.buffer = (u8*)0; i2c.length = 0; i2c.byte_cntr = 0; i2c.delay_cntr = 0; i2c.waitstate_state = 0; i2c.byte = 0; i2c.byte_bit_cntr = 8; } //----------------------- u8 I2C_Status(void) { return i2c.status; }; //---------- Transmit/Receive Block --------------------------- // The address is 8 bits, the LSBit ==1 for read, ==0 for write // u8 I2C_Action(u8 addr, u8 *data, u8 length) { u8 ret_val; ret_val = i2c.status; if(ret_val == I2C_READY) { i2c.buffer = data; i2c.length = length; i2c.address = addr; i2c.byte_cntr = 0; i2c.byte_bit_cntr = 8; i2c.status = I2C_BUSY; i2c.bus_state = I2C_BUS_STATE_START_0; } return ret_val; } //--------- Aux function used in the I2C state machine ------ void I2C_WaitStateCheck(void) { SET_SCL; // SCL high i2c.delay_cntr = 1; // Wait 1/2 bit i2c.waitstate_state = 1; // Check for SCL } //--------------------------------------------- // This function should be called from the interrupt // with the rate of 4xI2C_BITRATE void I2C_BitBanging(void) { // If there is a delay, do nothing // If waitstate, process waitstate // Else proceed to the state machine if(i2c.delay_cntr) { i2c.delay_cntr--; } else if((i2c.waitstate_state == 1)&&(!GET_SCL)) { i2c.waitstate_state = 2; i2c.delay_cntr = 1; } else if(i2c.waitstate_state == 2) { if(GET_SCL) i2c.waitstate_state = 0; i2c.delay_cntr = 1; } else { i2c.waitstate_state = 0; switch(i2c.bus_state) { //----- I2C in idle = do nothing ------ case I2C_BUS_STATE_IDLE: default: break; //---------- Start sequence -------- case I2C_BUS_STATE_START_0: I2C_WaitStateCheck(); i2c.bus_state = I2C_BUS_STATE_START_1; break; case I2C_BUS_STATE_START_1: CLR_SDA; i2c.delay_cntr = 1; i2c.bus_state = I2C_BUS_STATE_TX_0; i2c.byte = i2c.address; i2c.byte_bit_cntr = 8; i2c.byte_cntr = 0; break; //------------- Transmit byte -------- case I2C_BUS_STATE_TX_0: CLR_SCL; i2c.bus_state = I2C_BUS_STATE_TX_1; break; case I2C_BUS_STATE_TX_1: if(i2c.byte&0x80) SET_SDA; else CLR_SDA; i2c.byte <<= 1; i2c.bus_state = I2C_BUS_STATE_TX_3; break; case I2C_BUS_STATE_TX_3: I2C_WaitStateCheck(); i2c.byte_bit_cntr--; if(!i2c.byte_bit_cntr) { i2c.byte_bit_cntr = 8; i2c.bus_state = I2C_BUS_STATE_TX_4; // Read ACK } else // Transmit next bit in the byte { i2c.bus_state = I2C_BUS_STATE_TX_0; } break; // Read ACK from the slave case I2C_BUS_STATE_TX_4: CLR_SCL; i2c.bus_state = I2C_BUS_STATE_TX_5; break; case I2C_BUS_STATE_TX_5: SET_SDA; // Release SDA only when SCL is low i2c.bus_state = I2C_BUS_STATE_TX_6; break; case I2C_BUS_STATE_TX_6: I2C_WaitStateCheck(); i2c.bus_state = I2C_BUS_STATE_TX_7; break; case I2C_BUS_STATE_TX_7: // Here we can read ACK // ask = GET_SDA; CLR_SCL; if(i2c.address&0x01) // To read sequence { if(i2c.length) { i2c.delay_cntr = 1; i2c.bus_state = I2C_BUS_STATE_RX_1; } else { i2c.bus_state = I2C_BUS_STATE_STOP_1; } } else // Write sequence { if(i2c.byte_cntr >= i2c.length) // End of data { i2c.bus_state = I2C_BUS_STATE_STOP_1; } else // To next byte for transmission { i2c.byte = i2c.buffer[i2c.byte_cntr]; i2c.byte_cntr++; i2c.bus_state = I2C_BUS_STATE_TX_1; } } break; //---------- I2C STOP processing ------------- case I2C_BUS_STATE_STOP_1: CLR_SDA; i2c.bus_state = I2C_BUS_STATE_STOP_2; break; case I2C_BUS_STATE_STOP_2: I2C_WaitStateCheck(); i2c.bus_state = I2C_BUS_STATE_STOP_3; break; case I2C_BUS_STATE_STOP_3: SET_SDA; i2c.delay_cntr = 7; i2c.bus_state = I2C_BUS_STATE_STOP_4; break; case I2C_BUS_STATE_STOP_4: // Stop is complete i2c.status = I2C_READY; i2c.bus_state = I2C_BUS_STATE_IDLE; break; //--------- I2C master read processing -------- case I2C_BUS_STATE_RX_1: I2C_WaitStateCheck(); i2c.bus_state = I2C_BUS_STATE_RX_2; break; case I2C_BUS_STATE_RX_2: i2c.byte = ((i2c.byte<<1) | GET_SDA)&0xFF; CLR_SCL; i2c.byte_bit_cntr--; if(!i2c.byte_bit_cntr) { i2c.byte_bit_cntr = 8; i2c.buffer[i2c.byte_cntr] = i2c.byte; i2c.byte_cntr++; i2c.bus_state = I2C_BUS_STATE_RX_3; } else { i2c.delay_cntr = 1; i2c.bus_state = I2C_BUS_STATE_RX_1; } break; // Send ACK/NAK when a byte is received case I2C_BUS_STATE_RX_3: if(i2c.byte_cntr >= i2c.length) // last byte - NAK { SET_SDA; } else // ACK { CLR_SDA; } i2c.bus_state = I2C_BUS_STATE_RX_4; break; case I2C_BUS_STATE_RX_4: I2C_WaitStateCheck(); i2c.bus_state = I2C_BUS_STATE_RX_5; break; case I2C_BUS_STATE_RX_5: CLR_SCL; i2c.bus_state = I2C_BUS_STATE_RX_6; break; case I2C_BUS_STATE_RX_6: if(i2c.byte_cntr >= i2c.length) // last byte { CLR_SDA; i2c.bus_state = I2C_BUS_STATE_STOP_2; } else // Next byte { SET_SDA; i2c.bus_state = I2C_BUS_STATE_RX_1; } break; } } } //=========== <END>==============
Vladimir Vassilevsky wrote:
> > > StephieU wrote: > >> I'm working with a DSP (TMS320C2407) and we downloaded some code to >> 'create' or emulate an i2c bus - however, after downloading the zip files >> and trying to build the project it looks like the file >> >> stb.lib is missing >> >> and their are many other compile errors including (see below). If anyone >> has any comments or suggestions - this would be VERY helpful. Thanks! >> > > Implementing software bit banging I2C master is trivial. Scrap the > useless stuff that you have downloaded and implement the I2C from the > scratch. > > Vladimir Vassilevsky > > DSP and Mixed Signal Design Consultant > > http://www.abvolt.com > > > P.S. Here is the implementation. > > //====================== File i2c.h =========== > > #ifndef __I2C_MACHINE_H_INCLUDED > #define __I2C_MACHINE_H_INCLUDED > > /* Interrupt driven I2C master */ > /* (c) Abvolt. Ltd */ > /* VLV 2005 */
... Aww... I knew in my heart that you're an old softie. :-) Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;
StephieU wrote:
> I'm working with a DSP (TMS320C2407) and we downloaded some code to > 'create' or emulate an i2c bus - however, after downloading the zip files > and trying to build the project it looks like the file > > stb.lib is missing > > and their are many other compile errors including (see below). If anyone > has any comments or suggestions - this would be VERY helpful. Thanks! >
Where did you get the code? If it is from TI then call them.
Vladimir,

Thank you so much for your help.  My home computer is not set up with code
composer so I will try it first thing tomorrow.

How the i2c is used made complete sense until we attempted to interface it
with the dsp.  We thought the code TI provided would give us somewhere to
begin with but after spending hours trying to figure out what the code was
doing and not having it even work for their "demo" we began thinking it was
next to impossible, especially for somebody at our skill level.

Again, thank you so much for your help.

Sincerely,
Stephanie N Uhlich

PS: after trying "customer service" at National Semiconductor a month ago
we figured TI would be another waste of time.
StephieU wrote:

   ...

> PS: after trying "customer service" at National Semiconductor a month ago > we figured TI would be another waste of time.
Give them a chance to show themselves one way or the other. Good luck! Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;
StephieU wrote:
> I'm working with a DSP (TMS320C2407) and we downloaded some code to > 'create' or emulate an i2c bus - however, after downloading the zip files > and trying to build the project it looks like the file > > stb.lib is missing > > and their are many other compile errors including (see below). If anyone > has any comments or suggestions - this would be VERY helpful. Thanks! > > > > dspcl se2pd.c -g -v2xx -as -i..\include -i..\..\clib\include > -i..\..\..\..\stb_lib\clib\include > [se2pd.c] > TMS320C2x/C2xx/C5x ANSI C Compiler Version 7.00 > Copyright (c) 1987-1999 Texas Instruments Incorporated > "..\include\cdemo.h", line 30: [E045] cannot open include file > <regs240x.h> > "..\include\cdemo.h", line 33: [W048] #warn 'Assumed CLKIN--> 7.5 MHz for > TMS320F240x, 5MHz for TMS320F24x' > "..\include\cdemo.h", line 34: [W048] #warn 'Modify if not--> > SYSTEM_INI_PERIOD,PWMDAC_PERIOD,SCSR1_REG_VALUE ' > "..\include\cdemo.h", line 61: [E045] cannot open include file <STB.H> > "se2pd.c", line 45: [F001] syntax error at or near symbol 'wdog' > "se2pd.c", line 45: [F108] 'WATCHDOG_DEFAULTS' undefined > "se2pd.c", line 45: [F098] declaration must have type or storage class > "se2pd.c" ==> main > "se2pd.c" ==> c_int03 > "se2pd.c", line 110: [F108] 'EVAIFRB' undefined > "se2pd.c" ==> RstInit > "se2pd.c", line 153: [F109] structure or union type required > "se2pd.c", line 154: [F109] structure or union type required > "se2pd.c", line 162: [F108] 'WSGR' undefined > "se2pd.c", line 169: [F108] 'SCSR1' undefined > "se2pd.c", line 172: [F108] 'EVAIMRB' undefined > "se2pd.c", line 173: [F108] 'EVAIFRA' undefined > "se2pd.c", line 174: [F108] 'EVAIFRB' undefined > "se2pd.c", line 175: [F108] 'EVAIFRC' undefined > "se2pd.c", line 176: [F108] 'EVBIFRA' undefined > "se2pd.c", line 177: [F108] 'EVBIFRB' undefined > "se2pd.c", line 178: [F108] 'EVBIFRC' undefined > "se2pd.c", line 185: [F108] 'IMR' undefined > "se2pd.c" ==> time_base_init > "se2pd.c", line 226: [F108] 'T2CON' undefined > "se2pd.c", line 227: [F108] 'T2PR' undefined > "se2pd.c" ==> phantom > > dsplnk se2pd.mak > TMS320C1x/C2x/C2xx/C5x COFF Linker Version 7.00 > Copyright (c) 1987-1999 Texas Instruments Incorporated > > >> se2pd.mak, line 66: can't find input file stb.lib > Build Complete, > 21 Errors, 2 Warnings.
stb.lib and stb.h are files from "C24x Software Test Bench (STB) Library" available at TI's site. I am not sure what is and where can you get cdemo.h, but I assume you have downloaded it just the path is incorrect. You should take a look at "Communications Driver Library" also available at TI's site, where you already have I2C driver. Regards, Mitja