I am working with Q2687RD with firmware 7.47.
I need to read data from spi but adl_busRead always read 0, also if i connect the SPI1-I to 2,8V supply
I have already tested the SPI1-I GPIO28 as gpio and i can read the pin status 0 or 1.
The code is as follow
/***************************************************************************/
/* File : new_project.c */
/*-------------------------------------------------------------------------*/
/* Object : Customer application */
/* */
/* contents : Customer main procedures */
/* */
/***************************************************************************/
#include "wm_types.h"
#include "adl_str.h"
#include "adl_port.h"
#include "adl_traces.h"
#include "adl_AppliInit.h"
#include "adl_global.h"
#include "adl_sms.h"
#include "adl_RspHandler.h"
#include "adl_TimerHandler.h"
#include "adl_gpio.h"
#include "adl_bus.h"
// Application tasks prototypes
extern void main_task ( void );
void SpiCommInit(void);
void SpiTxInit(u8 txBytes,u8 rxBytes);
void comm_TimerHandler ( u8 ID, void * Context );
void SlaveSelect(bool select);
/*****************************************************************************/
// Definizioni
#define READ_SIZE 4
// Handshake GPIO
#define SLAVE_SELECT 19
#define SLAVE_READY 24 //ex 31
#define GPIO_SPI_COUNT 2
#define SPI_INTERFACE 1
#define RX_BUFFER_SIZE 100
/*****************************************************************************/
// Variabili
// SPI subscription data
adl_busSPISettings_t SpiConfig =
{
127, // 13/(1+n) per n=0->127 100KHz
// 12, // 13/(1+n) per n=0->127 1MHZ
ADL_BUS_SPI_CLK_MODE_0,
ADL_BUS_SPI_ADDR_CS_NONE,
ADL_BUS_SPI_CS_POL_LOW,
ADL_BUS_SPI_MSB_FIRST,
ADL_BUS_SPI_LOAD_UNUSED,
ADL_BUS_SPI_DATA_UNIDIR,
ADL_BUS_SPI_MASTER_MODE,
ADL_BUS_SPI_BUSY_UNUSED
};
s32 spiHandle;
s32 gpioHandle;
adl_busAccess_t accessConfig={0,0};
adl_ioDefs_t gpioReadyConfig[GPIO_SPI_COUNT]={
ADL_IO_GPIO|SLAVE_SELECT|ADL_IO_DIR_OUT|ADL_IO_LEV_HIGH,
ADL_IO_GPIO|SLAVE_READY|ADL_IO_DIR_IN
};
u8 rxBuffer[RX_BUFFER_SIZE];
u8 rxCounter=0;
u8 rxLen;
#ifndef __GNU_GCC__
/*****************************************************************************/
/* Macro : DECLARE_CALL_STACK */
/*---------------------------------------------------------------------------*/
/* Object : The GCC compiler and GNU Newlib (standard C library) */
/* implementation require more stack size than ARM compilers. If */
/* the GCC compiler is used, the Open AT® application has to be */
/* declared with greater stack sizes. */
/* */
/*---------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilization */
/*--------------------+---+---+---+------------------------------------------*/
/* X | X | | | required stack size */
/*--------------------+---+---+---+------------------------------------------*/
#define DECLARE_CALL_STACK(X) (X)
#else /* #ifndef __GNU_GCC__ */
#define DECLARE_CALL_STACK(X) (X*3)
#endif /* #ifndef __GNU_GCC__ */
// Application tasks declaration table
const adl_InitTasks_t adl_InitTasks [] =
{
{ main_task, DECLARE_CALL_STACK ( 1024 ), "main", 2 },
{ 0,0,0 }
};
/*****************************************************************************/
/* Function : main_task */
/*---------------------------------------------------------------------------*/
/* Object : Customer application initialization */
/* */
/*---------------------------------------------------------------------------*/
/*****************************************************************************/
void main_task ( void )
{
adl_InitType_e InitType = adl_InitGetType ();
SpiCommInit();
adl_tmrSubscribe ( TRUE, 10, ADL_TMR_TYPE_100MS, comm_TimerHandler );
}
void comm_TimerHandler ( u8 ID, void * Context )
{
wm_memset(rxBuffer,0xAA,RX_BUFFER_SIZE);
SpiTxInit(3);
}
/*****************************************************************************/
// Funzioni
void SpiTxInit(u8 rxBytes)
{
rxCounter=0;
rxLen=rxBytes;
SlaveSelect(true);
do
{
adl_busRead(spiHandle,&accessConfig,1,&rxBuffer[rxCounter]);
TRACE((2,"RxCounter: %d - Rx: 0x%X - Handle: %d", rxCounter,rxBuffer[rxCounter],spiHandle));
rxCounter++;
}
while(rxCounter<rxLen);
SlaveSelect(false);
}
void SlaveSelect(bool select)
{
s32 label=ADL_IO_GPIO |SLAVE_SELECT;
adl_ioWriteSingle(gpioHandle,&label,!select);
}
void SpiCommInit(void)
{
u32 addSize=0;
spiHandle=adl_busSubscribe(ADL_BUS_ID_SPI,SPI_INTERFACE,&SpiConfig);
adl_busIOCtl(spiHandle,ADL_BUS_CMD_SET_ADD_SIZE,&addSize);
gpioHandle=adl_ioSubscribe(GPIO_SPI_COUNT,gpioReadyConfig,0,0,0);
}