MCP23S17 Reading Problem With C2000

Thread Starter

Dragonoid

Joined Nov 27, 2017
55
Hi All,
I have interfaced an MCP23S17 With TMS320F28069 MCU and I am able to write to the System and output is being generated accordingly on port pins but there is a problem while reading from the register, it is always Zero.

C:
void SPI_Init(void)
{

        SpibRegs.SPIPRI.bit.TRIWIRE =1;//3-wire Mode
        SpibRegs.SPICCR.bit.SPICHAR = 0x7; // 16-bit char bits
        SpibRegs.SPICCR.bit.CLKPOLARITY = 0;
        SpibRegs.SPICTL.bit.CLK_PHASE = 0;
        SpibRegs.SPICTL.bit.MASTER_SLAVE = 1;
        SpibRegs.SPICTL.bit.TALK = 1; // Enable master mode, normal phase,
        // enable talk, and SPI int disabled.

        SpibRegs.SPIBRR = 63; // 15 -> 1Mbps
        SpibRegs.SPICCR.bit.SPISWRESET = 1; // Relinquish SPI from Reset
        SpibRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
C:
Uint16 SPI0_Write(unsigned char data)
{
Uint16 Send=0;
SpibRegs.SPITXBUF=(data<<8);
while(SpibRegs.SPISTS.bit.INT_FLAG ==0) {} // Wait until data received
Send = SpibRegs.SPIRXBUF;
return Send;

}
C:
void setup_MCP23S17()
{
    EALLOW;
   GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 0;  // RESET
   GpioCtrlRegs.GPADIR.bit.GPIO20 = 1;   // GPIO23 = output

   GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 0;  // CS
   GpioCtrlRegs.GPADIR.bit.GPIO21 = 1;   // GPIO6 = output
   EDIS;


   GpioDataRegs.GPADAT.bit.GPIO20=0;//RESET ENABLE
   DELAY_US(100);
   GpioDataRegs.GPADAT.bit.GPIO20=1;//RESET ENABLE
   DELAY_US(1000);

   MCP23S17_write(IOCON, 0x18);
   MCP23S17_write(IODIRA, 0x00);
   MCP23S17_write(IODIRB, 0xFF);
   MCP23S17_write(GPPUA, 0x00);
   MCP23S17_write(GPPUB, 0xF0);
   MCP23S17_write(IPOLA, 0xFF);
   MCP23S17_write(IPOLB, 0x00);
}


void MCP23S17_write(unsigned char address, unsigned char value)
{
    GpioDataRegs.GPADAT.bit.GPIO21=0;//CS ENABLE
    SPI0_Write(IO_DEVICE_ADDRESS_WRITE);
    SPI0_Write(address);
    SPI0_Write(value);
    GpioDataRegs.GPADAT.bit.GPIO21=1;//CS DISABLE
}


Uint16 MCP23S17_read(unsigned char address)
{
    Uint16 received_data = 0;
    GpioDataRegs.GPADAT.bit.GPIO21=0;//CS ENABLE
    SPI0_Write(IO_DEVICE_ADDRESS_READ);
    SPI0_Write(address);
    received_data=SPI0_Write(0);

    GpioDataRegs.GPADAT.bit.GPIO21=1;//CS DISABLE
    return received_data;
}
C:
         Temp=SPI0_Read(GPIOB);
 
Top