2 Replies Latest reply on Aug 18, 2017 3:01 PM by troels.brahe

    SPI

    troels.brahe

      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) >> 8) & 0xff) | 0b0 << 7 | 0b0 << 6 | 0b1 << 5 | 0b1 << 4)

          

      ...

          

      spi.xfer2([highByte[i],lowByte[i]])

         
         

       

         

      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 >> 8) & 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