spi programming with lmp91200

Discussion in 'The Projects Forum' started by mrinalini, Aug 28, 2012.

  1. mrinalini

    Thread Starter New Member

    Aug 28, 2012
    6
    0
    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:
    .
     
  2. DickCappels

    Moderator

    Aug 21, 2008
    2,647
    632
    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.
     
  3. mrinalini

    Thread Starter New Member

    Aug 28, 2012
    6
    0
    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.
     
  4. DickCappels

    Moderator

    Aug 21, 2008
    2,647
    632
    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.
     
  5. mrinalini

    Thread Starter New Member

    Aug 28, 2012
    6
    0
    [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....]

    Code ( (Unknown Language)):
    1.  
    2. /*
    3. buffer : spi buffer
    4. data_in : data to be read from spi
    5. data_out : data to be written to spi
    6. address : AFE sensor address pointer
    7. */
    8.  
    9. // LCD module connections
    10. sbit LCD_RS at RC1_bit;
    11. sbit LCD_EN at RC0_bit;
    12. sbit LCD_D4 at RD4_bit;
    13. sbit LCD_D5 at RD5_bit;
    14. sbit LCD_D6 at RD6_bit;
    15. sbit LCD_D7 at RD7_bit;
    16.  
    17. sbit LCD_RS_Direction at TRISC1_bit;
    18. sbit LCD_EN_Direction at TRISC0_bit;
    19. sbit LCD_D4_Direction at TRISD4_bit;
    20. sbit LCD_D5_Direction at TRISD5_bit;
    21. sbit LCD_D6_Direction at TRISD6_bit;
    22. sbit LCD_D7_Direction at TRISD7_bit;
    23. // LCD module connections
    24.  
    25.  
    26. char txt3[3],txt4[3];
    27. unsigned short data_in,address,buffer;
    28. unsigned int data_out=0XA880;
    29. unsigned char lowbyte,highbyte;
    30.  
    31. //Read data from memory array beginning at selected address
    32.  void READ(unsigned short address)
    33. {
    34.   lowbyte=data_out&0X00A8;
    35.   highbyte=data_out>>8;
    36.   PORTD.f2=0;                       // cs low
    37.   Spi1_read(0x03);                  // '0000 x011' READ Instruction
    38.   Spi1_Write(highbyte<<8/lowbyte);  // send address RDSR
    39.   //Spi1_Write(lowbyte);
    40.  // Spi1_Write(0x32);
    41.   data_in=Spi1_Read(buffer);        // READ data
    42.   PORTD.f2=1;                       // cs high
    43. }
    44.  
    45. //Reset the write enable latch (disable write operations)
    46. void WRDI()
    47. {
    48.   Spi1_Write(0x04);                 // '0000 x100' WRDI Instruction
    49. }
    50.  
    51. //Set the write enable latch (enable write operations)
    52. void WRENL()
    53. {
    54.   Spi1_Write(0x06);                 // '0000 x110' WREN Instruction
    55.   PORTD.f2=1;                       // cs high
    56.   PORTD.f2=0;                       // cs low
    57. }
    58.  
    59. //Write data to memory array beginning at selected address
    60. void WRITE(unsigned short address, unsigned short data_out)
    61. {
    62.   lowbyte=data_out&0X00A8;
    63.   highbyte=data_out>>8;
    64.  
    65.   PORTD.f2=0;                       // cs low
    66.   WRENL();
    67.   Spi1_Write(0x02);                 // '0000 x010' WRITE Instruction
    68.   Spi1_Write(address);              // send address
    69.   Spi1_Write(highbyte);             // send data
    70.   delay_ms(100);
    71.   Spi1_Write(address+1);
    72.   spi1_Write(lowbyte);
    73.   PORTD.f2=1;                       // cs high
    74.   WRDI();
    75. }
    76.  
    77.  
    78. void temperature()
    79. {
    80.         WRITE(0X00,0XA880);         // Write data 0XA880 TO AFE ADDRESS 0X00
    81.         delay_ms(10);
    82.         READ(0X00);                 // Read
    83.         PORTD=data_in;              // AND DISPLAY DATA ON PORTD
    84.         ByteToStr(data_in,txt3);
    85.         Lcd_Out(1,1,"TEMP:");
    86.         Lcd_Out(1,8,txt3);          // Write text in first row
    87.         Delay_ms(250);
    88. }
    89.  
    90. void init()
    91. {
    92.   PORTB = 0X00;
    93.   PORTD = 0X00;
    94.   TRISB = 0x00;
    95.   TRISD = 0x00;
    96.   SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    97.   delay_ms(500);
    98. }
    99.  
    100. void main()
    101. {
    102.      Lcd_Init();                    // Initialize LCD
    103.      init();
    104.      Lcd_Cmd(_LCD_CLEAR);           // Clear display
    105.      Lcd_Cmd(_LCD_CURSOR_OFF);
    106.      temperature();
    107. }
    108.  
     
    Last edited by a moderator: Sep 4, 2012
  6. DickCappels

    Moderator

    Aug 21, 2008
    2,647
    632
    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.
     
Loading...