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...
Error
Moderator: serg
-
- Posts: 12
- Joined: Tue Mar 22, 2011 9:46 am
Re: Error
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:
.
.
.
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:
.
.
.
-
- Posts: 12
- Joined: Tue Mar 22, 2011 9:46 am
Re: Error
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
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
-
- Posts: 12
- Joined: Tue Mar 22, 2011 9:46 am
Re: Error
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.
-
- Posts: 12
- Joined: Tue Mar 22, 2011 9:46 am
Re: Error
Actually I want read 1 byte data at a time. That is why I have given it as 1 in the sub_fifo_read().