Skip to content

Questions about SPI #1083

Answered by LeStarch
sheershak-agarwal asked this question in Q&A
Oct 21, 2021 · 1 comments · 9 replies
Discussion options

You must be logged in to vote

My understanding with SPI is that you read and write at the same time. Thus even if you are only required to write 16 bits, you still need to provide a buffer that is 16bits + 7*16bits long.

What happens if you try this:

char inBuf[2 + 14]; // in and out buffers should be the same size
Fw::Buffer in;
in.setData((U8*)inBuf);
in.setSize(sizeof(inBuf));

char buf[2 + 14] = { 0 };
buf[0] = 0x3E;
buf[1] = 0x00;

Fw::Buffer out;
out.setData((U8*)buf);
out.setSize(sizeof(buf));
this->SpiReadWrite_out(0,out,in);
printf("IMU bytes\n");
for (int i = 0; i < 16; i++) {
  printf("%x ", inBuf[i]);  // bytes likely in position 2 - 15, as device needs 16bit command before responding.
}
printf("\n");

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@LeStarch
Comment options

@sheershak-agarwal
Comment options

@sheershak-agarwal
Comment options

@LeStarch
Comment options

@sheershak-agarwal
Comment options

Answer selected by sheershak-agarwal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants