Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32 bit data transfer? #60

Open
mateusz-kusmierz opened this issue Jul 6, 2020 · 1 comment
Open

32 bit data transfer? #60

mateusz-kusmierz opened this issue Jul 6, 2020 · 1 comment

Comments

@mateusz-kusmierz
Copy link

mateusz-kusmierz commented Jul 6, 2020

I'm using teensy 4.1

Is it possible to send 32 bit data as shown here?
0b00000000000000000000000000000111 is beeing sent out (DATA-blue, CS-red, CLK-yellow)
IMG_20200706_193856 (Kopiowanie)

Because currently I can only manage to get this using this SPI.h library:
IMG_20200706_221629

and this code:

 SPI1.beginTransaction(settings);
SPI1.transfer(0x00);
SPI1.transfer(0x00);
SPI1.transfer(0xFF);
SPI1.transfer(0x00);
SPI1.endTransaction();

Clock distortion after 8 bits, and CS high, is issue for me.
As far as I know teensy 4.1 processor should be able to do 32bit SPI data transfers.

Regards Mateusz

@mateusz-kusmierz
Copy link
Author

mateusz-kusmierz commented Jul 6, 2020

I have modified SPI.h library and added transfer32 function starting in line 1258 after transfer16 function is finished.

uint32_t transfer32(uint32_t data) {
		uint32_t tcr = port().TCR;
		port().TCR = (tcr & 0xfffff000) | LPSPI_TCR_FRAMESZ(31);  // turn on 16 bit mode 
		port().TDR = data;		// output 16 bit data.
		while ((port().RSR & LPSPI_RSR_RXEMPTY)) ;	// wait while the RSR fifo is empty...
		port().TCR = tcr;	// restore back
		return port().RDR;
	}

This works, however I did not test it for receiving 32 bits of stream. Only sending.
Sending 32bits works great.
Here is code for sending:

#include <SPI.h>

SPISettings settings(1000000, MSBFIRST, SPI_MODE0);

void setup()
{
  SPI1.setMOSI(26);
  SPI1.setMISO(1);
  SPI1.setSCK(27);
  SPI1.setCS(0);
  SPI1.begin();
}

void loop()
{
  delay(100);
 SPI1.beginTransaction(settings);
SPI1.transfer32(0b11100000000000000000000000000111);
SPI1.endTransaction();
}

Result:
IMG_20200706_230322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant