Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions app/src/spi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "main.h"
#include "robotconfig.h"


typedef struct {
SPI_HandleTypeDef* spiHandle;
GPIO_TypeDef* csPort;
uint16_t csPin; //esto directamente nose, pero venia en un ejemplo que vi
} SPI_Config;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No es tan necesario. porque en teoría ya está definido en el robot config


SPI_Config SPI1_Config = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Igual, no hay necesidad de inicializarla

.spiHandle = &hspi1,
.csPort = SPI1_CS_PORT,
.csPin = SPI1_CS_PIN
};

// Inicia SPI
void SPI_Init(SPI_Config* config) {
HAL_GPIO_WritePin(config->csPort, config->csPin, GPIO_PIN_SET);
}

// envia y recibe
uint8_t SPI_Transfer(SPI_Config* config, uint8_t data) {
uint8_t receivedData;
HAL_GPIO_WritePin(config->csPort, config->csPin, GPIO_PIN_RESET);
HAL_SPI_TransmitReceive(config->spiHandle, &data, &receivedData, 1, HAL_MAX_DELAY);
HAL_GPIO_WritePin(config->csPort, config->csPin, GPIO_PIN_SET);
return receivedData;
}

int main(void) {
HAL_Init();
tim(); //voy a creer que es lo del relog
MX_GPIO_Init();
MX_SPI1_Init();


SPI_Init(&SPI1_Config);

while (1) {

uint8_t command = 0x01;
uint8_t response = SPI_Transfer(&SPI1_Config, command);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increíble, jaja
Eso es más que nada para mandar, pero aún no has especificado el comando...
Pregúntale a Anita cuál es el comando que tienes que enviar para que el IMU te de datos
Igual, lo que más importa es la lectura


HAL_Delay(1000); // awanta 1 segundo
}
}
2 changes: 1 addition & 1 deletion robotConfig
Submodule robotConfig updated 1 files
+0 −34 inc/robotPins.h