74 for(i=0;i<nQuantity;i++)
78 int SpiRW( u32 unPeripheralAddressSPI,
unsigned int unCPHA,
unsigned int unCPOL,
79 u8* auchWriteBuf, u8* auchReadBuf,
int unNumBytes, u8 uchCsActiveHigh )
103 unsigned int unControlData = 0x00000186;
106 unControlData = unControlData | (unCPHA << 4);
107 unControlData = unControlData | (unCPOL << 3);
110 XSpi_WriteReg(unPeripheralAddressSPI, 0x60, unControlData);
113 if( uchCsActiveHigh )
114 XSpi_WriteReg(unPeripheralAddressSPI, 0x70, 0xFFFFFFFE);
116 XSpi_WriteReg(unPeripheralAddressSPI, 0x70, 0xFFFFFFFF);
118 for( i = 0; i < unNumBytes; i++)
120 if( auchWriteBuf != 0 )
123 XSpi_WriteReg(unPeripheralAddressSPI, 0x68, auchWriteBuf[ i ]);
129 XSpi_WriteReg(unPeripheralAddressSPI, 0x68, 0x00);
133 XSpi_WriteReg(unPeripheralAddressSPI, 0x60, unControlData);
136 if( uchCsActiveHigh )
137 XSpi_WriteReg(unPeripheralAddressSPI, 0x70, 0xFFFFFFFF);
139 XSpi_WriteReg(unPeripheralAddressSPI, 0x70, 0xFFFFFFFE);
142 XSpi_WriteReg(unPeripheralAddressSPI, 0x60, unControlData & 0xFFFFFEFF);
145 while( !(XSpi_ReadReg( unPeripheralAddressSPI, 0x64 ) & 0x00000004) )
149 XSpi_WriteReg(unPeripheralAddressSPI, 0x60, unControlData);
152 if( (auchReadBuf != 0) )
154 auchReadBuf[ i ] = XSpi_ReadReg(unPeripheralAddressSPI, 0x6C);
158 if( uchCsActiveHigh )
159 XSpi_WriteReg(unPeripheralAddressSPI, 0x70, 0xFFFFFFFE);
161 XSpi_WriteReg(unPeripheralAddressSPI, 0x70, 0xFFFFFFFF);
180 for(i=0;i<nStopValue;i++)
203 for(i=0;i<nNumberOfTimes;i++)
207 uchLedStatus = 1 << j;
208 XGpio_DiscreteWrite(pLED_GPIO, 1, uchLedStatus);
214 uchLedStatus = 8 >> j;
215 XGpio_DiscreteWrite(pLED_GPIO, 1, uchLedStatus);
241 XGpio xGpioPmodPortMuxIO;
242 u8 uchPmodPortSelectBits=0;
254 uchPmodPortSelectBits = (uchPmodPortD << 6) + (uchPmodPortC << 4) + (uchPmodPortB << 2) + uchPmodPortA;
256 XGpio_Initialize(&xGpioPmodPortMuxIO, XPAR_AXI_GPIO_2_DEVICE_ID);
257 XGpio_SetDataDirection(&xGpioPmodPortMuxIO, 1, 0x00);
258 XGpio_DiscreteWrite(&xGpioPmodPortMuxIO, 1, uchPmodPortSelectBits);
273 XGpio xGpioPmodPortA;
274 unsigned int unGpioPortData = 0;
275 int nReturnVal=FALSE;
281 XGpio_Initialize(&xGpioPmodPortA, XPAR_AXI_GPIO_0_DEVICE_ID);
282 XGpio_SetDataDirection(&xGpioPmodPortA, 1, 0x0C);
283 unGpioPortData = XGpio_DiscreteRead(&xGpioPmodPortA, 1);
284 if(((unGpioPortData >> 2) & 0x03)==0x03)
286 printf(
"I2C Device is present\r\n");
293 printf(
"******WARNING: Could not find pull-ups on SDA nor SCL ********************\r\n");
294 printf(
"******Attempts to read/write may hang CPU ********************************\r\n");
295 printf(
"******Recommend to go back to main menu and double-check I2C device.******\r\n");
329 for(i=1;i<nExponent;i++)
331 nValue = nValue * nBase;
349 int nReturnVal = TRUE;
354 while(XUartLite_IsReceiveEmpty(unUartAddress) && (j < nTimeoutInTenthsOfSeconds))
360 if(XUartLite_IsReceiveEmpty(unUartAddress))
364 uchInput = XUartLite_RecvByte(unUartAddress);
368 if(XUartLite_IsReceiveEmpty(unUartAddress))
372 uchInput = XUartLite_RecvByte(unUartAddress);
375 if(XUartLite_IsReceiveEmpty(unUartAddress))
379 uchInput = XUartLite_RecvByte(unUartAddress);
387 *uchRxData = uchInput;
393 int GetLine(
char* sInputString,
unsigned int unMaxSize )
406 unsigned int unInputStringIndex = 0;
409 while( (uchInputChar !=
'\r') && (uchInputChar !=
'\n') && (unInputStringIndex < unMaxSize-1) )
411 sInputString[ unInputStringIndex ] = (char)uchInputChar;
412 unInputStringIndex++;
415 sInputString[ unInputStringIndex ] =
'\0';
417 return (unInputStringIndex < unMaxSize) ? unInputStringIndex : -1;
420 void printf_temp(
float fTemp, u8 uchPrintCelsius, u8 uchAddCarriageReturn)
434 if(uchPrintCelsius==TRUE)
435 printf(
"%.1f deg C",fTemp);
437 printf(
"%.1f deg F",((fTemp*1.8f)+32.0f));
438 if(uchAddCarriageReturn==TRUE)
453 uchInput = XUartLite_RecvByte(nUartAddress);
462 for(uchCount=0;uchCount<100;uchCount++)
464 switch(sStr[uchCount])
466 case '0': nRet=nRet<<4; nRet=nRet+0;
break;
467 case '1': nRet=nRet<<4; nRet=nRet+1;
break;
468 case '2': nRet=nRet<<4; nRet=nRet+2;
break;
469 case '3': nRet=nRet<<4; nRet=nRet+3;
break;
470 case '4': nRet=nRet<<4; nRet=nRet+4;
break;
471 case '5': nRet=nRet<<4; nRet=nRet+5;
break;
472 case '6': nRet=nRet<<4; nRet=nRet+6;
break;
473 case '7': nRet=nRet<<4; nRet=nRet+7;
break;
474 case '8': nRet=nRet<<4; nRet=nRet+8;
break;
475 case '9': nRet=nRet<<4; nRet=nRet+9;
break;
476 case 'a': nRet=nRet<<4; nRet=nRet+10;
break;
477 case 'b': nRet=nRet<<4; nRet=nRet+11;
break;
478 case 'c': nRet=nRet<<4; nRet=nRet+12;
break;
479 case 'd': nRet=nRet<<4; nRet=nRet+13;
break;
480 case 'e': nRet=nRet<<4; nRet=nRet+14;
break;
481 case 'f': nRet=nRet<<4; nRet=nRet+15;
break;
482 case 'A': nRet=nRet<<4; nRet=nRet+10;
break;
483 case 'B': nRet=nRet<<4; nRet=nRet+11;
break;
484 case 'C': nRet=nRet<<4; nRet=nRet+12;
break;
485 case 'D': nRet=nRet<<4; nRet=nRet+13;
break;
486 case 'E': nRet=nRet<<4; nRet=nRet+14;
break;
487 case 'F': nRet=nRet<<4; nRet=nRet+15;
break;
488 default: uchEnd=1;
break;