cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Hi all, I need to transfer two bytes of data to a SPI slave as fast as possible. The slave is a MCP4921 DAC. In a related application, I've done this with a Raspberry Pi in python like this:

   

 

   
    

lowByte.append(int(i/setAmplitude) & 0b11111111)
highByte.append(((int(i/setAmplitude) >> 😎 & 0xff) | 0b0 << 7 | 0b0 << 6 | 0b1 << 5 | 0b1 << 4)

    

...

    

spi.xfer2([highByte,lowByte])

   
   

 

   

The transfer from the PSoC is part of a BLE system; the value I want to send over SPI like this comes from a "Heart rate collector" on the PSoC 4 (it's not actually heart rate the sensor measures, but the profile is useful enough)

   

This is what I've written in the PSoC code:

   

 

   
    

int HR = HrscGetHeartRate();

    

...

    

uint8 mTxBuffer[2];
mTxBuffer[0] = HR & 0b11111111;
mTxBuffer[1] = (((HR >> 😎 & 0xFF) | 0b0 << 7 | 0b0 << 6 | 0b1 << 5 | 0b1 << 4);
DBG_PRINTF("\n%X\n", mTxBuffer[0]);
DBG_PRINTF("%X\n", mTxBuffer[1]);
SPIM_PutArray(mTxBuffer, 2);

   
   

 

   

As you can see, I'm printing the contents of the buffer to Termite to verify its contents, and it does look like the bytes are the values I'd expect. However, on the MCP4921 output, I don't see anything of interest. I've connected a sine wave generator to my sensor board's input, and using the PSoC's own IDAC I see a decent representation of this sine wave, but for the MCP I just see GND. Am I missing something obvious here? Thanks

0 Likes
Reply
1 Solution
Esteemed Contributor II

In Raspberry example you are transmitting the high byte first, in PSoC example last.

   

 

   

Bob

View solution in original post

0 Likes
Reply
2 Replies
Esteemed Contributor II

In Raspberry example you are transmitting the high byte first, in PSoC example last.

   

 

   

Bob

View solution in original post

0 Likes
Reply
Anonymous
Not applicable

Thanks, this fixed it!

0 Likes
Reply