Code C - [expand] 1 2 3 4 5 6 7 8 unsigned int lowbyte, highbyte, result; highbyte = ADRESL; highbyte = highbyte << 8; lowbyte = ADRESH; highbyte = highbyte | lowbyte; result = highbyte;
I haven't worked with the 18 series but with the 16, 24, 33ds.
If I remember right in the 10 bits operation the data is AdressL (8 less significant bits), AdressH (2 most significant bits) and not the contrary.
Maybe your problem is there.
You have choosen Left justified for ADC result.
So your low byte is ADRESH and high byte is ADRESL.
Code C - [expand] 1 2 3 4 5 6 7 8 unsigned int lowbyte, highbyte, result; highbyte = ADRESL; highbyte = highbyte << 8; lowbyte = ADRESH; highbyte = highbyte | lowbyte; result = highbyte;
Then send ADRESL and ADRESH and at destination compose this two 8 bit in on 16 bit value(integer)Above code may be correct but in SPI protocol we can send only 8bit at a time. But result contain 16 bit.
Thanks.
Then send ADRESL and ADRESH and at destination compose this two 8 bit in on 16 bit value(integer)
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 LATDbits.LATD0 = 0; //Slave select while(SSPSTATbits.BF == 0); //wait untill the buffer is full var1 = SSPBUF; LATDbits.LATD0 = 1; delay highbyte = var1; highbyte = highbyte << 8; LATDbits.LATD0 = 0; while(SSPSTATbits.BF == 0); var2 = SSPBUF; LATDbits.LATD0 = 1; delay lowbyte = var2; highbyte = highbyte | lowbyte; result = highbyte;
CS = Low
SPI_Write ADRESH
SPI_Write ADRESL
CS = High
Fix of lacmannmarcel's code
I think the above code will not work.
Because when we select a slave(CS = low) it can write only 8bit.
so in order to write 2byte we have to select the slave two times(as in my sample code).
Thanks,
sid
SPI can send 8bit data at a time.No need to make slave low and high two times. You can send 8 bits 2 times with 2 write operations. Can you show your full master and slave codes?
You can do more than one spi write operation between toggling of CS.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?