Microblaze and SPI problem

Jul 11, 2006 0 Replies

I got a strange problem with microblaze and SPI. I have based my program upon xspi_low_level_example.c



What happens is that when I run it with XSP_LOOPBACK_OPTION, then the da= ta =



that are being sent are read back. But when I remove the loopback, it on= ly =



reads 0xFF. The input pin (MISO) is floating (measures 0 when I look at = =



the pin with a oscilloscope). The same also happens when I select anothe= r =



pin for MISO. Basically it should have read 0x00 when the pin is low all= =



the time.



I'm using EDK 8.1 and the Spartan 3E starter kit Does anyone have a suggestion of how I can get it to read data properly?=


The important part of the code:



----------------------------------------------------------- //Initialize SPI status =3D XSpi_Initialize(&Spi, XPAR_SPI_ADCBOARD_DEVICE_ID); if (status =3D=3D XST_SUCCESS) {xil_printf("SPI Initialize successful\= r\n");} if (status =3D=3D XST_DEVICE_NOT_FOUND) {xil_printf("SPI device was no= t =



found in the configuration\r\n");}



status =3D XSpi_SelfTest(&Spi); if (status =3D=3D XST_SUCCESS) {xil_printf("SPI selftest successful\r\= n");} if (status =3D=3D XST_REGISTER_ERROR) {xil_printf("SPI register did no= t read =



or write correctly\r\n");} if (status =3D=3D XST_LOOPBACK_ERROR) {xil_printf("SPI loopback error = =



occurred\r\n");}


//Configure the SPI interface against the ADC. status =3D XSpi_SetOptions(&Spi, XSP_MASTER_OPTION | =



XSP_MANUAL_SSELECT_OPTION); if (status !=3D XST_SUCCESS) {xil_printf("ERROR: Failed to set SPI =



Options");}



status =3D XSpi_Start(&Spi); if (status !=3D XST_SUCCESS) {xil_printf("ERROR: Failed to start SPI")= ;}



=

while(1) { k=3DXGpio_DiscreteRead(&gp_dip_in,CHANNEL); XGpio_DiscreteWrite(&gp_led_out,CHANNEL,k);



=

//CONFIG DATA Xuint8 adc_config[2], bogus_data[2]; bogus_data[0]=3D1; bogus_data[1]=3D2; adc_config[0]=3Dk; adc_config[1]=3Dk+1; =



spi_transfer(adc_config,bogus_data,2); xil_printf("ADC write byte %d (0x%X)\r\n",adc_config[0],adc_config[0]);=



xil_printf("ADC read byte %d (0x%X)\r\n",bogus_data[0],bogus_data[0]); xil_printf("ADC write byte %d (0x%X)\r\n",adc_config[1],adc_config[1]);=



xil_printf("ADC read byte %d (0x%X)\r\n",bogus_data[1],bogus_data[1]); } =



}


void spi_transfer(Xuint8 *send, Xuint8 *recv, Xuint8 num_bytes) { int NumBytesRcvd =3D 0; int NumBytesSent =3D 0;



while(num_bytes--) { XSpi_mSendByte(XPAR_SPI_ADCBOARD_BASEADDR, *send++); NumBytesSent++; }



XSpi_mEnable(XPAR_SPI_ADCBOARD_BASEADDR);



while (!(XSpi_mGetStatusReg(XPAR_SPI_ADCBOARD_BASEADDR) & =



XSP_SR_TX_EMPTY_MASK));


while ((XSpi_mGetStatusReg(XPAR_SPI_ADCBOARD_BASEADDR) & =



XSP_SR_RX_EMPTY_MASK) =3D=3D 0) { *recv++ =3D XSpi_mRecvByte(XPAR_SPI_ADCBOARD_BASEADDR); NumBytesRcvd++; }



if ((NumBytesSent !=3D NumBytesRcvd) || (NumBytesSent =3D=3D 0)) { print("SPI XFER ERROR"); } }


Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required