EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

F2012, SPI and EEPRoms

Started by Vincent Crabtree February 13, 2008
Hi,
I'm new here and experimenting with the ez430. I tried searching but it
seems the I2C eeproms are more popular and there is little info on the
F2012.

I hooked up a Nokia 3310 LCD using SPI bit bang code by Marcel Cremmel to my
F2012, which worked great, but now need to put the font and Graphics data in
an
EEPROM to save code memory for actual code.

I found the application note on SPI for the CC2050, but I would like to use
the same port pin for both Data out and Data in due to small device. My
25LC512 EEPROM has the DOut pin connected to the Din Pin via 10k ohm
resistor, which connects to the F2012. The idea was to keep the F2012
SPI_Data pin as output when writing to LCD, but when reading from EEPROM the
pin would be output during the write command and 16 bit Address write, then
switch to high impedance and read the P1IN register.

However, when reading data all I am getting is 0xff.

Does this all sound good or am I doing something silly? The USI peripheral
is even more confusing for an MSP430 newbie, hence the bitbang to start.

Thanks for your help, Vincent

Code snippet is below:-

// Bit Bang SPI Send Byte, rising edge clock, MSB first
void SPISendByte(unsigned char Data){

unsigned char i;

for (i=0; i<8; i++) {
if ((Data & 0x80)==0) P1OUT &= ~SPI_D_Pin;
else P1OUT |= SPI_D_Pin;
Data <<= 1;
P1OUT |= SPI_CLK_Pin;
P1OUT &= ~SPI_CLK_Pin;
}
}

// Bit Bang SPI Get Byte, rising edge clock, MSB first
unsigned char SPIGetByte(void){

unsigned char Data; unsigned char i;

// make SPI Data pin three state
P1DIR &= ~SPI_D_Pin;
Data = 0;

for (i=0; i<8; i++) {
P1OUT &= ~SPI_CLK_Pin;
P1OUT |= SPI_CLK_Pin;
// test pin
Data = Data << 1;

if( P1IN & SPI_D_Pin ){
Data |= 0x01;
}

}
P1OUT &= ~SPI_CLK_Pin;
// restore SPI Data pin output
P1DIR |= SPI_D_Pin;
return Data;
}

// Read NV Single Byte - not efficient
unsigned char NVReadByte(unsigned int addr){

unsigned char i;

P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV

SPISendByte(NV_READ); // send read command
SPISendByte(addr >> 8); // send hi byte
SPISendByte(addr & 0xff ); // send Lo byte

i = SPIGetByte();

P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV

return i;
}

// Write Single Byte - not efficient
void NVWriteByte(unsigned int addr, unsigned int data){

P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV

SPISendByte(NV_WREN); // send read command

P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
_NOP(); // Gap
P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV

SPISendByte((addr & 0x0ff00) >> 8); // send hi byte
SPISendByte(addr & 0xff ); // send Lo byte
SPISendByte(data); // data byte

P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
_NOP(); // Gap

// Disable write latch
P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV
SPISendByte(NV_WRDI); // send disable command

P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV

}

// Get NV Busy Status
unsigned char NVStatus(void){

unsigned char i;

P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV

SPISendByte(NV_RDSR); // send read command

i = SPIGetByte();

P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV

return i ;

}

Beginning Microcontrollers with the MSP430

Hello!

When using 2 SPI devices on the same SPI port, you should simply use the
chip select of each device. When the LCD is selected, then the SPI port
talks to the LCD and when the memory is selected then it talks to the
memory.
I suppose that the CPU will be master:

- Connect your CPU data out to LCD_MOSI and MEM_MOSI
- Connect your CPU data in to LCD_MISO and MEM_MISO (1)
- Connect one control pin to LCD_CS
- Connect nother control pin to MEM_CS.

(1) I'm not sure you can read the display's DRAM. If you cannot, there is simply
no LCD_MISO.

Pascal
--- In m..., "Vincent Crabtree" wrote:
>
> Hi,
> I'm new here and experimenting with the ez430. I tried searching but it
> seems the I2C eeproms are more popular and there is little info on the
> F2012.
>
> I hooked up a Nokia 3310 LCD using SPI bit bang code by Marcel Cremmel to my
> F2012, which worked great, but now need to put the font and Graphics data in
> an
> EEPROM to save code memory for actual code.
>
> I found the application note on SPI for the CC2050, but I would like to use
> the same port pin for both Data out and Data in due to small device. My
> 25LC512 EEPROM has the DOut pin connected to the Din Pin via 10k ohm
> resistor, which connects to the F2012. The idea was to keep the F2012
> SPI_Data pin as output when writing to LCD, but when reading from EEPROM the
> pin would be output during the write command and 16 bit Address write, then
> switch to high impedance and read the P1IN register.
>
> However, when reading data all I am getting is 0xff.
>
> Does this all sound good or am I doing something silly? The USI peripheral
> is even more confusing for an MSP430 newbie, hence the bitbang to start.
>
> Thanks for your help, Vincent
>
> Code snippet is below:-
>
> // Bit Bang SPI Send Byte, rising edge clock, MSB first
> void SPISendByte(unsigned char Data){
>
> unsigned char i;
>
> for (i=0; i<8; i++) {
> if ((Data & 0x80)==0) P1OUT &= ~SPI_D_Pin;
> else P1OUT |= SPI_D_Pin;
> Data <<= 1;
> P1OUT |= SPI_CLK_Pin;
> P1OUT &= ~SPI_CLK_Pin;
> }
> }
>
> // Bit Bang SPI Get Byte, rising edge clock, MSB first
> unsigned char SPIGetByte(void){
>
> unsigned char Data; unsigned char i;
>
> // make SPI Data pin three state
> P1DIR &= ~SPI_D_Pin;
> Data = 0;
>
> for (i=0; i<8; i++) {
> P1OUT &= ~SPI_CLK_Pin;
> P1OUT |= SPI_CLK_Pin;
> // test pin
> Data = Data << 1;
>
> if( P1IN & SPI_D_Pin ){
> Data |= 0x01;
> }
>
> }
> P1OUT &= ~SPI_CLK_Pin;
> // restore SPI Data pin output
> P1DIR |= SPI_D_Pin;
> return Data;
> }
>
> // Read NV Single Byte - not efficient
> unsigned char NVReadByte(unsigned int addr){
>
> unsigned char i;
>
> P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV
>
> SPISendByte(NV_READ); // send read command
> SPISendByte(addr >> 8); // send hi byte
> SPISendByte(addr & 0xff ); // send Lo byte
>
> i = SPIGetByte();
>
> P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
>
> return i;
> }
>
> // Write Single Byte - not efficient
> void NVWriteByte(unsigned int addr, unsigned int data){
>
> P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV
>
> SPISendByte(NV_WREN); // send read command
>
> P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
> _NOP(); // Gap
> P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV
>
> SPISendByte((addr & 0x0ff00) >> 8); // send hi byte
> SPISendByte(addr & 0xff ); // send Lo byte
> SPISendByte(data); // data byte
>
> P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
> _NOP(); // Gap
>
> // Disable write latch
> P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV
> SPISendByte(NV_WRDI); // send disable command
>
> P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
>
> }
>
> // Get NV Busy Status
> unsigned char NVStatus(void){
>
> unsigned char i;
>
> P1OUT &= ~NV_CE_Pin; // Take CE pin low, Enable NV
>
> SPISendByte(NV_RDSR); // send read command
>
> i = SPIGetByte();
>
> P1OUT |= NV_CE_Pin; // Take CE pin Hi, Disable NV
>
> return i ;
>
> }
>

The 2024 Embedded Online Conference