SPI init neverending Reboot


#1

Hi,

if I run the following program on my Fastrack supreme it always reboots, and
I can not stop it with “at+wopen=0”.

It seems that the problem is the MCP23S17_Init(). if I undocument this function
in the adl_main, and call the function with “at+aeinit” everything is working fine.

I need that MCP23S17_Init() is called after every reboot automatically.

Have you any suggestion for me ???

Thanks
armin

#include “adl_global.h”

#define CMD_INIT “at+aeinit”
#define CMD_READ “at+aeread”

const u16 wm_apmCustomStackSize = 1024;

const adl_busSPISettings_t MySPIConfig =
{
1,
ADL_BUS_SPI_CLK_MODE_1,
ADL_BUS_SPI_ADDR_CS_GPIO, // ADL_BUS_SPI_ADDR_CS_HARD,
ADL_BUS_SPI_CS_POL_LOW,
ADL_BUS_SPI_MSB_FIRST,
ADL_IO_Q2687_GPIO_31,
ADL_BUS_SPI_FRAME_HANDLING, // ADL_BUS_SPI_WORD_HANDLING,
ADL_BUS_SPI_DATA_UNIDIR
};

#define WRITE_SIZE 5
#define READ_SIZE 3

adl_busAccess_t AccessConfig =
{
0,
0,
0,
0,
ADL_BUS_SIZE_BYTE
};

s32 MySPIHandle = -1;

u8 WriteBuffer[WRITE_SIZE];
u8 ReadBuffer[READ_SIZE];

u8 MCP23S17_INPUT(void);

void MCP23S17_Write(u8 u1,u8 u2,u8 u3);
void MCP23S17_Init(void);

void HelloWorld_TimerHandler ( u8 ID )
{
char lStr[50];

adl_atSendResponse ( ADL_AT_UNS, "Timer\r\n" );

}

u8 MCP23S17_INPUT(void)
{
char lStr[50];

u8 opcode = 0x41;
u8 address = 0x12;

u8 OpcodeMax = 32;
u8 AddressMax = 32;

AccessConfig.OpcodeLength = 8;
AccessConfig.Opcode = opcode << ( OpcodeMax - AccessConfig.OpcodeLength );
AccessConfig.AddressLength = 8;
AccessConfig.Address = address << ( AddressMax - AccessConfig.AddressLength );

s32 lErr = adl_busRead(MySPIHandle,&AccessConfig,1,ReadBuffer);

wm_sprintf(lStr,“SPI IN: %d Error: %d\r\n”,ReadBuffer[0],lErr);
adl_atSendResponse ( ADL_AT_UNS, lStr );

return ReadBuffer[0];
}

void MCP23S17_Write(u8 uOpcode,u8 uAddress,u8 u3)
{
char lStr[50];

WriteBuffer[0] = u3;

u8 OpcodeMax = 32;
u8 AddressMax = 32;

AccessConfig.OpcodeLength = 8;
AccessConfig.Opcode = uOpcode << ( OpcodeMax - AccessConfig.OpcodeLength );
AccessConfig.AddressLength = 8;
AccessConfig.Address = uAddress << ( AddressMax - AccessConfig.AddressLength );

AccessConfig.Size = ADL_BUS_SIZE_BYTE;

s32 lErr = adl_busWrite(MySPIHandle,&AccessConfig,1,WriteBuffer);

wm_sprintf(lStr,"SPI Out: %X %X %X    Error: %d\r\n",
                uOpcode,
                uAddress,
                u3,
                lErr);
adl_atSendResponse ( ADL_AT_UNS, lStr );

}

void MCP23S17_Init(void)
{
char lStr[50];

MySPIHandle = adl_busSubscribe(ADL_BUS_SPI1,(adl_busSettings_u *)&MySPIConfig);

wm_sprintf(lStr,"MySPIHandle: %d\r\n",MySPIHandle);
adl_atSendResponse ( ADL_AT_UNS, lStr );

MCP23S17_Write(0x40,0x0A,0x00);
MCP23S17_Write(0x40,0x00,0xFF);
MCP23S17_Write(0x40,0x01,0x00);
MCP23S17_Write(0x40,0x02,0x00);
MCP23S17_Write(0x40,0x03,0x00);
MCP23S17_Write(0x40,0x0C,0x00);
MCP23S17_Write(0x40,0x0D,0x00);   

}

void Cmd_INIT_Handler(adl_atCmdPreParser_t *paras)
{
adl_atSendResponse ( ADL_AT_UNS, “+Begin Init\r\n” );
MCP23S17_Init();
adl_atSendResponse ( ADL_AT_UNS, “+End Ini\r\n” );

adl_atSendStdResponse(ADL_AT_RSP,ADL_STR_OK);
}

void Cmd_READ_Handler(adl_atCmdPreParser_t *paras)
{
adl_atSendResponse ( ADL_AT_UNS, “+Begin Read\r\n” );
MCP23S17_INPUT();
adl_atSendResponse ( ADL_AT_UNS, “+End Read\r\n” );

adl_atSendStdResponse(ADL_AT_RSP,ADL_STR_OK);
}

void adl_main ( adl_InitType_e InitType )
{
/* Set 1s cyclic timer */

adl_atSendResponse ( ADL_AT_UNS, "Restart\r\n" );

adl_atCmdSubscribe ( CMD_INIT,(adl_atCmdHandler_t)Cmd_INIT_Handler,ADL_CMD_TYPE_ACT);
adl_atCmdSubscribe ( CMD_READ,(adl_atCmdHandler_t)Cmd_READ_Handler,ADL_CMD_TYPE_ACT);

adl_tmrSubscribe ( TRUE, 50, ADL_TMR_TYPE_100MS, HelloWorld_TimerHandler );

MCP23S17_Init();
}