Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

User7878
Level 1
Level 1
Hi there,
I´m trying to create some code where is used SPI to communicate with booths ISOFACE ( IN and OUT) and use CANBUS too.
But I have some problems here.
1º If I use only the routine to communicate with ISOFACE OUT the code runs well. But when I put the code to ISOFACE IN the routine of ISOFACE OUT stops with status "Timeout".
I green on this.
This is my code.... Can anyone tell me what's can cause that or what can be done to fix this?

/*
* Main.c
*
* Created on: 8 de Fev de 2014
* Author: Luis
*/


#include //Declarations from DAVE3 Code Generation (includes SFR declaration)



/* Thread IDs */
osThreadId tid_thread0; /* assigned ID for thread 1 */
osThreadId tid_thread1; /* assigned ID for thread 1 */
osThreadId tid_thread2; /* assigned ID for thread 2 */

osSemaphoreDef(TestSem);
osSemaphoreId Sem;

int32_t timer1;
int32_t timer2;

uint8_t Readdata[256];
uint8_t ReadpageCmd[4];

void osTimer_thread(void const *argument);
void t1_thread(void const *argument);
void t2_thread(void const *argument);


void Write_Isoface(uint16_t data);
uint16_t Read_Isoface();


void Timer_10ms_CallBack(void const *arg);
void Timer_100ms_CallBack(void const *arg);

osTimerDef(Timer1, Timer_10ms_CallBack);
osTimerDef(Timer2, Timer_100ms_CallBack);



uint32_t exec1, exec2;


SPI002_ChConfigType Channel_wrData =
{
.Direction = SPI002_SRC_CHANNEL,
.Mode = SPI002_CH_STANDARD,
.DataCount = 1,
.DummyData = 0xFFFF
};

SPI002_ChConfigType Channel_dummy_Data =
{
.Direction = SPI002_SRC_CHANNEL,
.Mode = SPI002_CH_STANDARD,
.DataCount = 1,
.DummyData = 0xFFFF
};

SPI002_ChConfigType Channel_ReadpageCmd =
{
.Direction = SPI002_SRC_CHANNEL,
.Mode = SPI002_CH_STANDARD,
.DataCount = 4,
.DummyData = 0xFFFF
};
SPI002_ChConfigType Channel_Readpage =
{
.Direction = SPI002_DEST_CHANNEL,
.Mode = SPI002_CH_STANDARD,
.DataCount = 256,
.DummyData = 0xFFFF
};

osThreadDef(osTimer_thread, osPriorityNormal, 1, 0);
osThreadDef(t1_thread, osPriorityNormal, 1, 0);
osThreadDef(t2_thread, osPriorityNormal, 1, 0);



/*----------------------------------------------------------------------------
* Thread 1: Send thread
*---------------------------------------------------------------------------*/
void t1_thread(void const *argument) {
for (;;) {
osDelay(100);
IO004_TogglePin(IO004_Handle0);
Read_Isoface();

}
/* We are done here, exit this thread */
}


/*----------------------------------------------------------------------------
* Thread 2: Receive thread
*---------------------------------------------------------------------------*/
void t2_thread(void const *argument) {

status_t status;

Write_Isoface(0);
Readdata[0]=0x55;
Readdata[1]=0xAA;
for (;;) {

Write_Isoface((uint16_t)Readdata[0]);
osDelay(100);
Write_Isoface((uint16_t)Readdata[1]);
osDelay(100);
}
}

/*----------------------------------------------------------------------------
* T Timer_10ms_CallBack
*---------------------------------------------------------------------------*/

void osTimer_thread(void const *argument) {
osTimerId id1, id2;
osStatus status;
uint32_t timerDelay;

exec1 = 1;
exec2 = 2;
id1 = osTimerCreate(osTimer(Timer1), osTimerPeriodic, &exec1);
if (id1) {
timerDelay = 50;
status = osTimerStart(id1, timerDelay); // start timer
if (status != osOK) {
// Timer could not be started
}
}
id2 = osTimerCreate(osTimer(Timer2), osTimerPeriodic, &exec2);
if (id2) {
timerDelay = 100;
status = osTimerStart(id2, timerDelay); // start timer
if (status != osOK) {
// Timer could not be started
}
}
}

/*----------------------------------------------------------------------------
* T Timer_10ms_CallBack
*---------------------------------------------------------------------------*/
void Timer_10ms_CallBack(void const *arg) {

timer1++;

}
/*----------------------------------------------------------------------------
* Timer_100ms_CallBack
*---------------------------------------------------------------------------*/
void Timer_100ms_CallBack(void const *arg) {

timer2++;

}
/*----------------------------------------------------------------------------
* Main
*---------------------------------------------------------------------------*/
int main(void)
{
// status_t status; // Declaration of return variable for DAVE3 APIs (toggle comment if required)


DAVE_Init(); // Initialization of DAVE Apps


tid_thread0 = osThreadCreate(osThread(osTimer_thread), NULL);
tid_thread1 = osThreadCreate(osThread(t1_thread), NULL);
tid_thread2 = osThreadCreate(osThread(t2_thread), NULL);

osKernelStart();
osDelay(osWaitForever);

while(1)
{

}
return 0;
}

uint16_t Read_Isoface() {
volatile uint32_t Status;
SPI002_JobConfigType JobHandle;
Channel_Readpage.ChDataPtr = (uint16_t*)&Readdata;

SPI002_LocalStructureInit(&SPI002_Handle0,SPI002_JOB2,&JobHandle,56);
ReadpageCmd[0]=0xFF;

SPI002_SetupChannel(&JobHandle,SPI002_JOB_CH1,&Channel_ReadpageCmd);
SPI002_SetupChannel(&JobHandle,SPI002_JOB_CH2,&Channel_Readpage);
JobHandle.FrameLen = 8;

SPI002_StartJob(&JobHandle,500);
Status = SPI002_WaitForJobCompletion(&JobHandle,500);
if(Status != DAVEApp_SUCCESS)
while(1);
Status = SPI002_GetJobStatus(&JobHandle);
if(Status != SPI002_JOB_OK )
while(1);

}



void Write_Isoface(uint16_t Data) {

volatile uint32_t Status;
uint16_t Write;
SPI002_JobConfigType JobHandle;

Write=Data;
Channel_wrData.ChDataPtr = (uint16_t*)&Write;
SPI002_LocalStructureInit(&SPI002_Handle0,SPI002_JOB1,&JobHandle,55);

/* This job sends 0x55 to the ISOFACE LEDs */
SPI002_SetupChannel(&JobHandle,SPI002_JOB_CH1,&Channel_wrData);
JobHandle.FrameLen = 8;
JobHandle.WordLen=8;


SPI002_StartJob(&JobHandle,500);
Status = SPI002_WaitForJobCompletion(&JobHandle,500);
if(Status != DAVEApp_SUCCESS)
while(1);
Status = SPI002_GetJobStatus(&JobHandle);
if(Status != SPI002_JOB_OK )
while(1);




}


Regards
Luis Silva
1 Reply
Not applicable
Hi Luis Silva,

I have forwarded your question to one of our colleague who has experience on ISOFACE applications. Will update you once got reply.

Best regards,
Sophia
0 Likes