I am trying to set my SPI communication with a PIC18F452 from Microchip in order to send an 8-byte array to the bus (= transfer of all the bytes at once). Here is an example of what my array looks like :
array 0x0080 byte
array 0x0080 0x01
array 0x0081 0x01
array 0x0082 '\0'
array 0x0083 0x01
array 0x0084 0x01
array 0x0085 0x01
array 0x0086 0x01
array 0x0087 '\0'
/// SEND DATA TO SPI
SPI_INT = 0; // Enable SS
SPI_INT = 1; // Disable SS
delay_ms(); // Delay
Eventually and in order to achieve my goal, I have completely changed my method to solve this problem.
I still use SPI for the communication. But instead of an array, I save the value of my input signal (after all the operations I apply to it) in a value. This value is later separate in two parts that will be send one byte one to the bus.
// Definition unsigned int value = 0; unsigned char value_byte1 = 0; unsigned char value_byte2 = 0; unsigned int onTheBus_byte1 = 0; unsigned int onTheBus_byte2 = 0; // In main function, the value is modified using a counter (value++;) // Transfer to SPI value_byte1 = value >> 8; value_byte2 = value & 0xFF; SPI_INT = 0; // Enable SS onTheBus_byte1 = WriteSPI(value_byte1); onTheBus_byte2 = WriteSPI(value_byte2); SPI_INT = 1; // Disable SS
So, if I get :
value = 1505 (= 0x05E1)
in the main loop, then
value_byte1 = 0x05 value_byte2 = 0xE1
(This code has been tested on Proteus, and I do see both bytes on the SPI debugger when the value is written on the bus)
In case I need to use the value, say on another pic, I assemble the two parts after I have read them :
value = (value_byte1 << 8) | value_byte2;