I'm working with SPI and temperature Xilinx SDK sensor TC77, everything during subprogram-, where I Get the proper temperature except the need to get the proper temperature, but the output is "temperature ... what can be a replication error,
#include" xparameters.h "#include" xspi include .h "# include" xspi_l.h "#include" stdio.h "#include" xstatus.h "# & lt; stdlib.h & gt; #include" xil_cache.h "#include" xbasic_types.h "#define SPI_DEVICE_ID XPAR_SPI_0_DEVICE_ID #define SPI_SELECT 0x01 # BUFFER_SIZE 8 Defined XSpi SpiInstance Rapt made, u8 SendBuffer [BUFFER_SIZE]; u8 RecvBuffer [BUFFER_SIZE]; int Spi_Test (XSpi * SpiInstancePtr, U 16 SpiDeviceId); int main (void) to {int status; (;;) {status = Spi_Test (& amp; SpiInstance, SPI_DEVICE_ID); if (status = XST_SUCCESS) {XST_FAILURE return;}!} return XST_SUCCESS;} int Spi_Test (XSpi * SpiInstancePtr, U 16 SpiDeviceId) {int position; int i, j; XSpi_Config * ConfigPtr; / * Pointer in the configuration data * / / ***** SPI driver ****** / ConfigPtr = start XSpi_LookupConfig (SPI_DEVICE_ID); If (ConfigPtr == NULL) {return XST_DEVICE_NOT_FOUND; } XSpi_CfgInitialize (SpiInstancePtr, ConfigPtr, ConfigPtr-> BaseEdress); XSpi_SetOptions (SpiInstancePtr, XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION); XSpi_GetSlaveSelect (SpiInstancePtr); XSpi_SetSlaveSelect (SpiInstancePtr, SPI_SELECT); XSpi_Start (SpiInstancePtr); XSpi_IntrGlobalDisable (SpiInstancePtr); / ***** Switch to continuous mode to get the temperature, connect MOSI pin ***** / / * SendBuffer [0] = 0x00; Send Buffer [1] = 0x00; Position = XSpi_Transfer (SpiInstancePtr, SendBuffer, RecvBuffer, 2); If (status! = XST_SUCCESS) {return XST_FAILURE; } * / / **** Get temperature in the rewobf [0] & amp; RECU-buffer [1] **** / XSPI transfers (SPEINESTENCENT, SENDBUFFER, RAVUBFER, 2); Xil_printf ("MSB of temperature register = 0x% x \ r \ n", founder [0]); Xil_printf ("LSB of temperature register is = 0x% x \ r \ n", probaber [1]); // sign bit method int sign = recover buffer [0] & amp; 0x80; Int tempValue = 0; Float Temple Celsius; If (sign == 0) {TempValue = (findbuf [0]
Saturday, 15 February 2014
C programing error with TC77 sensor -
You have not assigned an evaluation of
((([[0] and 0x7f) & lt; 8 | Rikkerberger [1])> 1) - 4096;
Do you code is meant to be the
if & the (signBit == 0) tempValue = (RecvBuffer [0] lt; & lt; ? 8 | Riviebufar [1]) & gt; & Gt; 3; Else tempValue = ((([[0] and 0x7f) & lt; 8 | Ruckbuffer [1]) >> 3) - 4096; Name tempCelsius = (float) tempValue * 0.0625; Xil_printf ("Temperature is =% F \ n \ r", Tempelius);
edit
I searched it and informed xil_printf ()
% support Does not f, it only supports% d, L, X, C, S. You have to print two integer in case of a positive value:
integer, thousandths; Whole = tempelius; Thousandth = (tempcelsius - entire) * 1000; Xil_printf ("% d.% 03d \ n", whole, thousandths);
In the document, xil_printf ()
: says "This function is like printf, but very small in size (only 1 kB). Support for Floating Point Numbers. "
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment