cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mubashira@12
Visitor
Visitor
1,007 Views
Registered: ‎08-04-2017

Error in SPI C code

I am trying to write data to AXI Quad SPI and then read it, I following the steps as shown in the images attached below. Now the problem is that the whole process works fine if i am manually inputting the values using peek poke but when i run my c code, it produces an error and i have no idea why there is an error when the same steps work manually. Can anybody please help me with this?

 

Here is my code for read and write:

void de_init()
{
fpga_write_word(virtual_base+0x70, 0x00);
fpga_write_word(virtual_base+0x60, 0x0E6);
fpga_write_word(virtual_base+0x70, 0x01);
fpga_write_word(virtual_base+0x60, 0x1E6);
}

void write_init()
{
//WRITE enable command sequence
fpga_write_word(virtual_base+0x60, 0x1E6);
fpga_write_word(virtual_base+0x68, 0x06);
de_init();
}

void qspi_read()
{
unsigned int rd_value;
int i;
int r=55;
int rd_err_count=0;
TRY
{
fpga_write_word(virtual_base+0x60, 0x0E6);
printf("Filling Data Trasmit register with dummy data\n");
write_init();
printf ("write_init works?]\n");
//for (i=1;i<=16;i++)
//{

fpga_write_word(virtual_base+0x68, r);
printf("Wrote 37 to SPI Data Transmit Register\n");
rd_value = fpga_read_word(virtual_base+0x74);
printf("Value of SPI Receive FIFO Occupancy Register: 0x%x\n",rd_value);
//}

de_init();
//for (i=1;i<=16;i++)
//{
rd_value = fpga_read_word(virtual_base+0x6c);
printf("Value received in SPI Data Receive register: 0x%x\n", rd_value);

rd_value = fpga_read_word(virtual_base+0x78);
printf("Value of SPI Receive FIFO Occupancy Register: 0x%x\n",rd_value);
//}
}
CATCH
{
rd_err_count+=1;
}
ETRY;
printf("\nThe errors in read are %d\n\n",rd_err_count);


}


void qspi_write(unsigned int wr_value[])
{

int i;
unsigned int rd_value;
int wr_err_count=0;
TRY
{
write_init();
for (i=1;i<=16;i++)
{

fpga_write_word(virtual_base+0x68, wr_value[i-1]);
printf("Writing %x to SPI Data Transmit Register\n",wr_value[i-1]);
rd_value = fpga_read_word(virtual_base+0x74);
printf("Value of SPI Receive FIFO Occupancy Register: 0x%x\n",rd_value);

}
de_init();
rd_value = fpga_read_word(virtual_base+0x74);
printf("Value of SPI Receive FIFO Occupancy Register: 0x%x\n",rd_value);
}
CATCH
{
wr_err_count+=1;
}
ETRY;
printf("\nThe errors in qspi_write are %d\n\n",wr_err_count);
}

 

And this is the error:

 

Filling Data Trasmit register with dummy data
Writing 37 to SPI DaUnhandled fault: external abort on non-linefetch (0x1018) at 0xb6d8c06c
ta Transmit Register
Value of SPI Receive FIFO Occupancy Registpgd = ee164000
er: 0x0
Writing 37 to SPI Data Transmit Register
Value of SPI [b6d8c06c] *pgd=2e87d831, *pte=41e00743Receive FIFO Occupancy Register: 0x1
Writing 37 to SPI Data Tra, *ppte=41e00c33
nsmit Register
Value of SPI Receive FIFO Occupancy Register: 0x2
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x3
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x4
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x5
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x6
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x7
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x8
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0x9
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0xa
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0xb
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0xc
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0xd
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0xe
Writing 37 to SPI Data Transmit Register
Value of SPI Receive FIFO Occupancy Register: 0xf
Bus error

Capture1.PNG
Capture2.PNG
0 Kudos
0 Replies