SPI transferBits(*data, *out, bits) sending strange

Pierre83
Posts: 3
Joined: Thu Oct 12, 2023 2:55 am

SPI transferBits(*data, *out, bits) sending strange

Postby Pierre83 » Thu Oct 12, 2023 4:17 pm

Hello,
This code:
uint16_t readSPI(uint8_t first, uint16_t last) {
CS_LOW_inline();
uint32_t ret = 0;
uint32_t *out = &ret;
uint32_t data = first << 16;
data |= last;
SPI.transferBits( data, out, 17); // here is the problem
CS_HIGH_inline();
return ret & 0x0FFF;
}
does not return bits from 16-0 but instead bits from 23-7 so I have to write SPI.transferBits( data, out, 24);
to obtain the last bits (which is my interest)

Is it normal ????
Thanks for your advices !!!!!!!
Pierre

Pierre83
Posts: 3
Joined: Thu Oct 12, 2023 2:55 am

Re: SPI transferBits(*data, *out, bits) sending strange

Postby Pierre83 » Tue Oct 17, 2023 10:44 am

Hello,

It seems that nobody uses is function ?????????
It could be usefull when using SPI devices which doesn't use 8bits dialog !!!!!!!!!!!

For me, i'm using an MCP3008 ( 10 bits ADC SPI ), and this device could use only 17bits instead of 24 to dialog with it's MCU and using this method could lead to a very fast sampling device !!!

ANY ADVICE ????????????????????????????

Thanks !

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI transferBits(*data, *out, bits) sending strange

Postby ESP_Sprite » Wed Oct 18, 2023 5:54 am

Kinda depends on what ESP you use. Some ESP32 types can only do SPI transactions in 8 bit increments.

Pierre83
Posts: 3
Joined: Thu Oct 12, 2023 2:55 am

Re: SPI transferBits(*data, *out, bits) sending strange

Postby Pierre83 » Wed Oct 18, 2023 2:53 pm

Thanks for your answer !

I'm using a Lolin32 Lite clone, may be it's concerned by the content of your answer ?

I'll try with another model of clone :( and tell you if this is the same situation !

Pierre

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI transferBits(*data, *out, bits) sending strange

Postby ESP_Sprite » Thu Oct 19, 2023 3:37 am

Hm, that chip uses the 'classic' ESP32, which should be capable of non-multiple-of-8-bit transactions. Sorry, then it's not your hardware and I don't know enough about the Arduino environment to tell you what the issue is.

Who is online

Users browsing this forum: lbernstone and 46 guests