spi programming with lmp91200

Thread Starter

mrinalini

Joined Aug 28, 2012
6
hi
i want to program lmp91200 with spi through pic 18f4523...

i only want to know about data_in and data_out and address for storing data .please help me this much:confused::confused::confused::confused:
.
 

DickCappels

Joined Aug 21, 2008
10,171
This is probably not the best forum to get that kind of specific help.

Below is the URL of a tutorial on the topic. You will have to tailor the data to the lmp91200 and what you want that chip to do.

http://microchippiclessons.blogspot.com/2009/06/spi-tutorial.html

All you really need to know is in the LMP91200 datasheet; you just have to read carefully.

SPI is about the simplest serial interface you can imagine: Put the first bit on the data pin, toggle the clock, put the next bit on the data pin... Yes, its that simple.
 

Thread Starter

mrinalini

Joined Aug 28, 2012
6
i have done spi programming between eeprom n pic and also with two pic 18f.

i want to program AFE sensor and pic through pic in which i want to knew that if i want configuration register of sensor to be 0XA880
so, i should write 16 bit(msb first and then lsb) to sensor and then read 16 bit.this will be correct thought process.
 

DickCappels

Joined Aug 21, 2008
10,171
I can't see where on the datasheet it specifies which way the shift occurs, but the only time I used SPI, I shifted the MSb. Once you have clocked the data into the shift register, take CSB high and that puts the data to work in the chip. You don't need to about reading the data back out because there is no serial output on this chip.

The "SERIAL CONTROL INTERFACE OPERATION" section of the data sheet is very terse and somewhat cryptic (like the data direction; maybe MSb first is default for SPI) but it looks like everything you need to know is there.
 

Thread Starter

mrinalini

Joined Aug 28, 2012
6
[i had done this with its programming help me out dick cappels for the next step...
i am getting value 168 at the LCD...where i am wrong...i am sorry for silly mistakes too as i am new too it....]

Rich (BB code):
/*
buffer : spi buffer
data_in : data to be read from spi
data_out : data to be written to spi
address : AFE sensor address pointer
*/

// LCD module connections
sbit LCD_RS at RC1_bit;
sbit LCD_EN at RC0_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISC1_bit;
sbit LCD_EN_Direction at TRISC0_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// LCD module connections


char txt3[3],txt4[3];
unsigned short data_in,address,buffer;
unsigned int data_out=0XA880;
unsigned char lowbyte,highbyte;

//Read data from memory array beginning at selected address
 void READ(unsigned short address)
{
  lowbyte=data_out&0X00A8;
  highbyte=data_out>>8;
  PORTD.f2=0;                       // cs low
  Spi1_read(0x03);                  // '0000 x011' READ Instruction
  Spi1_Write(highbyte<<8/lowbyte);  // send address RDSR
  //Spi1_Write(lowbyte);
 // Spi1_Write(0x32);
  data_in=Spi1_Read(buffer);        // READ data
  PORTD.f2=1;                       // cs high
}

//Reset the write enable latch (disable write operations)
void WRDI()
{
  Spi1_Write(0x04);                 // '0000 x100' WRDI Instruction
}

//Set the write enable latch (enable write operations)
void WRENL()
{
  Spi1_Write(0x06);                 // '0000 x110' WREN Instruction
  PORTD.f2=1;                       // cs high
  PORTD.f2=0;                       // cs low
}

//Write data to memory array beginning at selected address
void WRITE(unsigned short address, unsigned short data_out)
{
  lowbyte=data_out&0X00A8;
  highbyte=data_out>>8;
  
  PORTD.f2=0;                       // cs low
  WRENL();
  Spi1_Write(0x02);                 // '0000 x010' WRITE Instruction
  Spi1_Write(address);              // send address
  Spi1_Write(highbyte);             // send data
  delay_ms(100);
  Spi1_Write(address+1);
  spi1_Write(lowbyte);
  PORTD.f2=1;                       // cs high
  WRDI();
}


void temperature()
{
        WRITE(0X00,0XA880);         // Write data 0XA880 TO AFE ADDRESS 0X00
        delay_ms(10);
        READ(0X00);                 // Read
        PORTD=data_in;              // AND DISPLAY DATA ON PORTD
        ByteToStr(data_in,txt3);
        Lcd_Out(1,1,"TEMP:");
        Lcd_Out(1,8,txt3);          // Write text in first row
        Delay_ms(250);
}

void init()
{
  PORTB = 0X00;
  PORTD = 0X00;
  TRISB = 0x00;
  TRISD = 0x00;
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
  delay_ms(500);
}

void main()
{
     Lcd_Init();                    // Initialize LCD
     init();
     Lcd_Cmd(_LCD_CLEAR);           // Clear display
     Lcd_Cmd(_LCD_CURSOR_OFF);
     temperature();
}
 
Last edited by a moderator:

DickCappels

Joined Aug 21, 2008
10,171
I don't know if you are going to get much help with your code on this forum but you might find help in the Programmer's Corner forum on this website. I am glad you hear you managed to get your SPI to work.
 
Top