Post Go back to editing

Max31820

Category: Software
Hi Team,
   I want to interface Max31280 temperature sensor with TMS320 microcontroller. I wrote the code for communication. My reset function perform well. I got the presence signal back from the device. But when I send the read rom command the received value is 255. Here is my code
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
void Gpio_init();
void Gpio_write_bit(int data);
int Gpio_read_bit();
int system_reset();
int Gpio_read_byte();
void Gpio_write_byte(int data);
enum DELAY { A = 5, B = 70, C = 70, D = 5, E = 10, F = 53, G = 0, H = 480, I = 70, J = 410 };
enum COMMANDS { READ_ROM = 0x33, CONVERT = 0x44, READ_SCRATCHPAD = 0xBE,
                SKIP_ROM = 0xCC, WRITE_SCRATCHPAD = 0x4E, COPY_SCRATCHPAD = 0x48, MATCH_ROM = 0x55
              };
void main()
{
 int reset=0,i;
 int ROM_Code[64]={0};
InitSysCtrl();
InitScibGpio();
DINT;
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();
    // Enable CPU and PIE interrupts
    // This example function is found in the DSP2833x_PieCtrl.c file.
        EnableInterrupts();
Gpio_init();
reset=system_reset();
//data_value= Gpio_read_bit();
if(reset==0){while(1);}
else{Gpio_write_byte(READ_ROM );
        for ( i = 0; i < 64; ++i) {
            ROM_Code[i] = Gpio_read_byte();
        }
}
while(1);
}
int system_reset()
{
    int data=0;
    int flag=0;
    GpioDataRegs.GPACLEAR.bit.GPIO18=1;GpioDataRegs.GPASET.bit.GPIO18=0;
    //DELAY_US(480);
    DELAY_US(H);
    GpioDataRegs.GPACLEAR.bit.GPIO18=0;GpioDataRegs.GPASET.bit.GPIO18=1;
    //DELAY_US(70);
    DELAY_US(I);
    data= GpioDataRegs.GPADAT.bit.GPIO19;
    DELAY_US(J);
    if(data==0){flag=1;}
    else{flag=0;}
    //DELAY_US(1000);
return flag;
}
void Gpio_init()
{
    EALLOW;
    GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0;   // Enable pullup on GPIO18
    GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;   // Enable pullup on GPIO18
    GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 0;// select GPIO from mux
    GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 0;// select GPIO from mux
    GpioCtrlRegs.GPADIR.bit.GPIO18 = 1;// select direction as out
    GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;// select direction as in
   EDIS;
}
void Gpio_write_bit(int data)
{
    if(data==0){
        GpioDataRegs.GPACLEAR.bit.GPIO18=1;GpioDataRegs.GPASET.bit.GPIO18=0;
        DELAY_US(15);
        DELAY_US(45);
       // DELAY_US(C);
       // DELAY_US(D);
    }
    else {
    GpioDataRegs.GPASET.bit.GPIO18=0;GpioDataRegs.GPACLEAR.bit.GPIO18=1;
    DELAY_US(10);
    //DELAY_US(A);
    GpioDataRegs.GPASET.bit.GPIO18=1;GpioDataRegs.GPACLEAR.bit.GPIO18=0;
    DELAY_US(5);
    DELAY_US(45);
    //DELAY_US(B);
    }
    //DELAY_US(60);
   // DELAY_US(1);
    return;
}
int Gpio_read_bit()
{
    int temp_data;
   GpioDataRegs.GPASET.bit.GPIO18=0;GpioDataRegs.GPACLEAR.bit.GPIO18=1;
   DELAY_US(1);
   // DELAY_US(A);
  GpioDataRegs.GPASET.bit.GPIO18=1;GpioDataRegs.GPACLEAR.bit.GPIO18=0;
    //DELAY_US(E);
    DELAY_US(10);
    temp_data=GpioDataRegs.GPADAT.bit.GPIO19;
   // DELAY_US(F);
    DELAY_US(4);
    DELAY_US(45);
   //DELAY_US(1);
    return temp_data;
}
void Gpio_write_byte(int data)
{
   int i,buff;
for(i=0;i<8;i++)
{
    buff=data&0x01;
    Gpio_write_bit(buff);
    data=data>>1;
}
}
int Gpio_read_byte()
{
   int i,buff,temp_value=0;
for(i=0;i<8;i++)
{
    buff=Gpio_read_bit();
    temp_value|=(buff<<i);
}
return temp_value;
}
During read function, if I don't give 1 after give a 0 signal the read function will give all zeros. Kindly review my code and let me know the updates.
In hardware I have connected GPIO18 and GPIO19 of microcontroller  to one wire of Temperature sensor and 4.7 ohm pull up to Vcc.
Thanks
Anu

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.