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

ERCK 05SPI 360 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

ERCK 05SPI 360 #2

wants to merge 1 commit into from

Conversation

ShahzebA1i
Copy link
Contributor

ERCK SPI code to be reviewed.

This code attempts to establish SPI communication between an Arduino (as the master) and an SPI-compatible slave device. The program sends start bytes to the slave, retrieves data bytes, and optionally processes the received data (e.g., extracting a 14-bit value for further use).

Features
Configures the Arduino's SPI interface for communication.
Transmits start bytes (0xAA and 0xFF) to initiate communication with the slave.
Receives 4 data bytes from the slave device.
Extracts a 14-bit value from the received bytes for angle measurement.

Connections:
MOSI (Master Out, Slave In): Arduino pin 51.
SCK (Serial Clock): Arduino pin 52.
CS (Chip Select): Arduino pin 53 (defined in the code).

Code Description
Setup Phase - Initializes the SPI interface with:
Clock speed: 125 kHz (to accommodate slower slaves).
Bit order: Most Significant Bit (MSB) first.
SPI Mode: Mode 1 (Clock polarity and phase settings).
Configures the Chip Select (CS) pin to control the slave device.
Loop Phase:
Initiates communication by pulling the CS pin LOW. Sends start bytes (0xAA and 0xFF) to signal the slave to prepare data. Receives 4 data bytes (b1, b2, b3, b4) from the slave. Processes the first two bytes (b1 and b2) to extract a 14-bit value using bitwise operations and masking. Ends the communication by pulling the CS pin HIGH.

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

Successfully merging this pull request may close these issues.

1 participant