Hi everyone,
I'm trying to get better at programming through registers and understanding datasheets. Best way to learn is to practice.
I've challanged myself with getting the SPI working on a teensy 4.0 through direct register manipulation.
I've read the clocking, I/O and SPI chapters of the datasheet and i seem to have everything done. I must be missing a small detail or something because my code doesn't work.
My external sensor that the teensy 4.0 is connected to is an MPU9250. I want to point out that my wiring is correct because i have been able to use the SPI library and get it to work.
To verify that my code is working, i am simply trying to read the WHO_AM_I register.
My code is pretty well commented out (it's a learning project).
Basic Notes:
- I have configured the chip select as a digital i/o pin instead of it being controlled by SPI (i would rather control it through software for versatility)
- LPSPI4 is being used (all the normal teensy 4.0 SPI pins)
- Currently when i read the WHO_AM_I register, i first get 128 and then a whole bunch of 255's...
- SPI should work at 1 MHz
- Not sure how to understand what SCKDIV on page 2952 means.
- Current SPI clock is configured as 664 MHz from PLL3 PFD1 that gets divided by 6 to become 110 MHz. This still needs to drop to 1 MHz.
Any help from somehow who could look over my code and provide suggestions that may get it to work would be great! Code is attached to this post (it's long).
Thanks,
-Mark
I'm trying to get better at programming through registers and understanding datasheets. Best way to learn is to practice.
I've challanged myself with getting the SPI working on a teensy 4.0 through direct register manipulation.
I've read the clocking, I/O and SPI chapters of the datasheet and i seem to have everything done. I must be missing a small detail or something because my code doesn't work.
My external sensor that the teensy 4.0 is connected to is an MPU9250. I want to point out that my wiring is correct because i have been able to use the SPI library and get it to work.
To verify that my code is working, i am simply trying to read the WHO_AM_I register.
My code is pretty well commented out (it's a learning project).
Basic Notes:
- I have configured the chip select as a digital i/o pin instead of it being controlled by SPI (i would rather control it through software for versatility)
- LPSPI4 is being used (all the normal teensy 4.0 SPI pins)
- Currently when i read the WHO_AM_I register, i first get 128 and then a whole bunch of 255's...
- SPI should work at 1 MHz
- Not sure how to understand what SCKDIV on page 2952 means.
- Current SPI clock is configured as 664 MHz from PLL3 PFD1 that gets divided by 6 to become 110 MHz. This still needs to drop to 1 MHz.
Any help from somehow who could look over my code and provide suggestions that may get it to work would be great! Code is attached to this post (it's long).
Thanks,
-Mark