Error

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
sreejith6320
Posts: 12
Joined: Tue Mar 22, 2011 9:46 am

Error

Post by sreejith6320 »

I have sub-20 which is configured in slave mode. It is reading data from another board which is the master. So when I run my program to read the data send from master using FIFO read and write data into a file, sometimes it works correctly and sometimes it showing this
FIFO READ 64 bytes:

BULK_OUT 3 bytes:
02 61 00
Transfer completed, transferred=3
BULK_IN 7 bytes:
06 61 04 90 0f 01 80
FIFO READ 64 bytes:


Can any one tell me whether this is the problem of connection which i made or it is some bug in my code...

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Error

Post by xol »

From your description it is not clear what are you doing and what happens.

sreejith6320
Posts: 12
Joined: Tue Mar 22, 2011 9:46 am

Re: Error

Post by sreejith6320 »

I have a board which sends data to LCD through SPI. So I'm using sub-20 board for reading that data. Here sub-20 is configured as slave using this function
sub_spi_config( hndl, SPI_ENABLE|SPI_SLAVE|SPI_CPOL_FALL|SPI_SETUP_SMPL, 0 )
I'm using fifo read for reding the data. Since i need 1 byte at a time ,I've given it like this
rc = sub_fifo_read( hndl, in_buff,1,20000);
where rc in an int.
When I run this code, sometimes it works properly but sometimes it showing like this

FIFO READ 64 bytes:

BULK_OUT 3 bytes:
02 61 00
Transfer completed, transferred=3
BULK_IN 7 bytes:
06 61 04 80 0f 01 00
FIFO READ 64 bytes:

BULK_OUT 3 bytes:
02 61 00
Transfer completed, transferred=3
BULK_IN 7 bytes:
06 61 04 80 0f 01 00
FIFO READ 64 bytes:

.
.
.


xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Error

Post by xol »

How do you get this traces?
Do you run a loop? Show me the whole loop.

sreejith6320
Posts: 12
Joined: Tue Mar 22, 2011 9:46 am

Re: Error

Post by sreejith6320 »

I had used an infinite while loop

while(1)
{

rc = sub_fifo_read( hndl, in_buff,1,20000);
if (rc >= 0)
{
if(file_currBuff==0)
{
data_buff=file_buff1_data;
a0_buff=file_buff1_A0;
}
else
{
data_buff=file_buff2_data;
a0_buff=file_buff2_A0;
}
data_buff=in_buff[0];
status = sub_gpio_read( hndl, &gpio_val);
if (status != 0)
{
printf ("Error in gpio read");
}
A0_value=gpio_val & PIN(gpio_pin);
if(A0_value==0)
{
if(data_buff==START_FRAME)
{
if(flag==0)
{
flag=1;
}
else
{
file_endBuff=i-1;
i=0;
ret = pthread_create( &thread1, NULL,log_data, NULL);
if(ret!=0)
{
printf("Error in pthread");
}
if(file_currBuff==0)
{
file_currBuff=1;
}
else
{
file_currBuff=0;
}
flag=0;
continue;
}
}
a0_buff=0;

}
else
{
a0_buff=1;

}
i++;


}

else
{
continue;
}
}




here data_buff and a0_buff are unsigned char pointers and file_buff2_data,file_buff2_A0,file_buff1_data,file_buff1_A0 are 4 unsigned char arrays of size 1048

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Error

Post by xol »

OK,
Now tell me how do you get the trace? Do you turn it on or it shows up sporadically?

sreejith6320
Posts: 12
Joined: Tue Mar 22, 2011 9:46 am

Re: Error

Post by sreejith6320 »

When I execute the code, sometimes it works properly. But other times it is showing something I mentioned earlier. When that error comes I just unplugged sub-20 and tried once again , then it worked.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Error

Post by xol »

HI,
More likely you have a memory leakage that overwrite trace control variable.
First of all I suggest you to run
rc = sub_fifo_read( hndl, in_buff,64,20000);
It is not safe to use less then 64 bytes buffer.

sreejith6320
Posts: 12
Joined: Tue Mar 22, 2011 9:46 am

Re: Error

Post by sreejith6320 »

Actually I want read 1 byte data at a time. That is why I have given it as 1 in the sub_fifo_read().

Post Reply