27 Eylül 2017 Çarşamba

SPI Example Using TC77

Proteus: SPI is another digital bus to communicate multiple devices. We will read temperature through TC77 using SPI bus. I connected oscilloscope and SPI debugger for diagnostic purposes. Connections  :
PIC RC3 SCL clock --> TC77 SCK clock
PIC RC4 SDI input data --> TC77 I/O
PIC RC0 output --> TC77 CS chip select

Equipment in SPI is selected by making chip select port to Low.



MCC: internal osc 1Mhz selected, MSSP with SPI master selected. input data sampled at End, clock polarity is idle to active, clock edge active to idle. SPI clock is selected at 15.625khz. We also selected  RC0 as output pin for chip select on SPI bus. Nothing is selected in interrupt tab.





XC8: dont touch interrupts, everything is disabled.  We will set Low RC0 to enable communication with TC77. Then, read 8bits, twice. disable TC77 by setting RC0 high. TC77 uses 13bits with 0.0625 resolution. Thus multiply 0.0625 with 13 bits. It may need different formula for negative temperatures.


    unsigned char s1[10];
    uint8_t  TempLSB, TempMSB           = 0;
    
    OpenXLCD(FOUR_BIT & LINES_5X7);
    WriteCmdXLCD(DON&CURSOR_OFF&BLINK_OFF); 

    while (1)
    {
        // Add your application code
        //SPI_Exchange8bit(0x00);
        
        IO_RC0_SetLow(); 
        TempMSB = SPI_Exchange8bit(0x00);
        TempLSB = SPI_Exchange8bit(0x00);
        IO_RC0_SetHigh(); 

        sprintf(s1, "%3.1f", ((TempMSB<<8|TempLSB)>>3)*0.0625);   
    

        while(BusyXLCD());
        SetDDRamAddr(0x01); // clear LCD        
        putrsXLCD("TC77 Example");
        SetDDRamAddr(0x40); // goto second line
        while(BusyXLCD());
        putrsXLCD("Temp=");putrsXLCD(s1);
        __delay_ms(1000);
    }
}


Hiç yorum yok:

Yorum Gönder