working crude example

spi
polymurph 3 years ago
parent f678c41563
commit 734647f637

@ -35,18 +35,18 @@ typedef enum{
} spi_mode_t; } spi_mode_t;
typedef enum{ typedef enum{
NONINVERTED, SPI_NONINVERTED,
INVERTED SPI_INVERTED
}spi_clkPol_t; }spi_clkPol_t;
typedef enum{ typedef enum{
CAPTURE_ON_FIRST_CLK_TRANSITION, SPI_CAPTURE_ON_FIRST_CLK_TRANSITION,
CAPTURE_ON_SECCOND_CLK_TRANSITION SPI_CAPTURE_ON_SECCOND_CLK_TRANSITION
} spi_phase_t; } spi_phase_t;
typedef enum{ typedef enum{
MSB_FIRST, SPI_MSB_FIRST,
LSB_FIRST SPI_LSB_FIRST
}spi_framef_t; }spi_framef_t;
typedef enum{ typedef enum{
@ -61,8 +61,6 @@ typedef enum{
typedef struct{ typedef struct{
pinNo_t pin; /*!< pin number */ pinNo_t pin; /*!< pin number */
spiCH_t spi; /*!< spi hardware channel number */ spiCH_t spi; /*!< spi hardware channel number */
spi_framef_t format; /*!< spi format */
spi_clkPol_t clkPol; /*!< spi clock polarity*/
}spi_ch_t; }spi_ch_t;
typedef uint8_t (*readReg_t) (uint8_t); typedef uint8_t (*readReg_t) (uint8_t);
@ -74,11 +72,13 @@ typedef uint8_t (*readReg_t) (uint8_t);
* @brief This is the spi hardware channel class * @brief This is the spi hardware channel class
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
*/ */
void spiInitMaster(spiCH_t spi_hw_ch, void spiInitMaster(
spi_clkPol_t clockPolarity, spiCH_t spi_hw_ch,
spi_phase_t phase, spi_clkPol_t clockPolarity,
spi_framef_t frameFormat, spi_phase_t phase,
uint32_t prescaler); spi_framef_t frameFormat,
spi_comMode_t comMode,
uint32_t prescaler);
/** /**
@ -89,7 +89,10 @@ void spiInitMaster(spiCH_t spi_hw_ch,
* \param spi_hw_ch SPI hardware channel * \param spi_hw_ch SPI hardware channel
* \param chipslectPin designated pin for chipslect * \param chipslectPin designated pin for chipslect
*/ */
void spiSetupCH(spi_ch_t *ch, spiCH_t spi_hw_ch, pinNo_t chipselectPin); void spiSetupCH(
spi_ch_t *ch,
spiCH_t spi_hw_ch,
pinNo_t chipselectPin);
/** /**
* \brief Read register * \brief Read register
@ -98,8 +101,9 @@ void spiSetupCH(spi_ch_t *ch, spiCH_t spi_hw_ch, pinNo_t chipselectPin);
* \param reg_address register address * \param reg_address register address
* \return register content * \return register content
*/ */
uint8_t spiReadReg(spi_ch_t *spi_ch, uint8_t spiReadReg(
uint8_t reg_address); spi_ch_t *spi_ch,
uint8_t reg_address);
/** /**
* \brief Read Block * \brief Read Block
@ -111,10 +115,11 @@ uint8_t spiReadReg(spi_ch_t *spi_ch,
* \param *buffer pointer to the buffer in which the read content is written into * \param *buffer pointer to the buffer in which the read content is written into
* \param buf_len length of buffer * \param buf_len length of buffer
*/ */
void spiAutoReadBlock(spi_ch_t *spi_ch, void spiAutoReadBlock(
uint8_t start_address, spi_ch_t *spi_ch,
uint8_t* buffer, uint8_t start_address,
uint8_t buf_len); uint8_t* buffer,
uint8_t buf_len);
/** /**
* \brief Write register * \brief Write register
@ -124,9 +129,10 @@ void spiAutoReadBlock(spi_ch_t *spi_ch,
* \param data data byte to be written into register * \param data data byte to be written into register
* *
*/ */
void spiWriteReg(spi_ch_t *spi_ch, void spiWriteReg(
uint8_t reg_address, spi_ch_t *spi_ch,
uint8_t data); uint8_t reg_address,
uint8_t data);
/** /**
* \brief Write data block * \brief Write data block
* Write a block of data starting at a given start address. * Write a block of data starting at a given start address.
@ -137,56 +143,63 @@ void spiWriteReg(spi_ch_t *spi_ch,
* \param *data pointer to data to be written * \param *data pointer to data to be written
* \param data_len length of data to be written * \param data_len length of data to be written
*/ */
void spiWriteBlock(spi_ch_t *spi_ch, void spiWriteBlock(
uint8_t start_address, spi_ch_t *spi_ch,
const uint8_t *data, uint8_t start_address,
uint8_t data_len); const uint8_t *data,
uint8_t data_len);
/** /**
* \brief write 8 bits * \brief write 8 bits
* \param bits 8 bits * \param bits 8 bits
*/ */
void spiWrite8bit(spi_ch_t *spi_ch, void spiWrite8bit(
uint8_t bits); spi_ch_t *spi_ch,
uint8_t bits);
/** /**
* \brief read and write simultainously 8 bits * \brief read and write simultainously 8 bits
* \param bits 8 bits * \param bits 8 bits
* \return 8 bits * \return 8 bits
*/ */
uint8_t spiReadWrite8bit(spi_ch_t *spi_ch, uint8_t spiReadWrite8bit(
uint8_t bits); spi_ch_t *spi_ch,
uint8_t bits);
/** /**
* \brief write 16 bits * \brief write 16 bits
* \param bits 16 bits * \param bits 16 bits
*/ */
void spiWrite16bit(spi_ch_t *spi_ch, void spiWrite16bit(
uint16_t bits); spi_ch_t *spi_ch,
uint16_t bits);
/** /**
* \brief read and write simultainously 16 bits * \brief read and write simultainously 16 bits
* \param bits 16 bits * \param bits 16 bits
* \return 16 bits * \return 16 bits
*/ */
uint16_t spiReadWrite16bit(spi_ch_t *spi_ch, uint16_t spiReadWrite16bit(
uint16_t bits); spi_ch_t *spi_ch,
uint16_t bits);
/** /**
* \brief write 32 bits * \brief write 32 bits
* \param bits 32 bits * \param bits 32 bits
*/ */
void spiWrite32bit(spi_ch_t *spi_ch, void spiWrite32bit(
uint32_t bits); spi_ch_t *spi_ch,
uint32_t bits);
/** /**
* \brief read and write simultainously 32 bits * \brief read and write simultainously 32 bits
* \param bits 32 bits * \param bits 32 bits
* \return 32 bits * \return 32 bits
*/ */
uint32_t spiReadWrite32bit(spi_ch_t *spi_ch, uint32_t spiReadWrite32bit(
uint8_t bits); spi_ch_t *spi_ch,
uint8_t bits);
//implementation //implementation
@ -194,60 +207,72 @@ uint32_t spiReadWrite32bit(spi_ch_t *spi_ch,
* @brief SPI hardware peripheral reset * @brief SPI hardware peripheral reset
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
*/ */
void spiReset(spiCH_t spi_hw_ch); void spiReset(
spiCH_t spi_hw_ch);
/** /**
* @brief Enable Bus for SPI * @brief Enable Bus for SPI
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
*/ */
void spiEnableBus(spiCH_t spi_hw_ch); void spiEnableBus(
spiCH_t spi_hw_ch);
/** /**
* @brief Enable SPI hardware channel * @brief Enable SPI hardware channel
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
*/ */
void spiEnable(spiCH_t spi_hw_ch); void spiEnable(
spiCH_t spi_hw_ch);
/** /**
* @brief Dissable SPI hardware channel * @brief Dissable SPI hardware channel
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
*/ */
void spiDissable(spiCH_t spi_hw_ch); void spiDissable(
spiCH_t spi_hw_ch);
/** /**
* @brief Set SPI operation mode (MASTER or SLAVE) * @brief Set SPI operation mode (MASTER or SLAVE)
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param mode * @param mode
*/ */
void spiSetMode(spiCH_t spi_hw_ch, spi_mode_t mode); void spiSetMode(
spiCH_t spi_hw_ch,
spi_mode_t mode);
/** /**
* @brief Set SPI clock polarity * @brief Set SPI clock polarity
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param clkPol Clock polarity * @param clkPol Clock polarity
*/ */
void spiSetPolarity(spiCH_t spi_hw_ch, spi_clkPol_t clkPol); void spiSetPolarity(
spiCH_t spi_hw_ch,
spi_clkPol_t clkPol);
/** /**
* @breif Get SPI polarity * @breif Get SPI polarity
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @return polarity * @return polarity
*/ */
spi_clkPol_t spiGetPolarity(spiCH_t spi_hw_ch); spi_clkPol_t spiGetPolarity(
spiCH_t spi_hw_ch);
/** /**
* @brief Set SPI clock phase * @brief Set SPI clock phase
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param phase * @param phase
*/ */
void spiSetPhase(spiCH_t spi_hw_ch, spi_phase_t phase); void spiSetPhase(
spiCH_t spi_hw_ch,
spi_phase_t phase);
/** /**
* @brief Get SPI clock phase * @brief Get SPI clock phase
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @return phase * @return phase
*/ */
spi_phase_t spiGetPhase(spiCH_t spi_hw_ch); spi_phase_t spiGetPhase(
spiCH_t spi_hw_ch);
/** /**
@ -255,14 +280,17 @@ spi_phase_t spiGetPhase(spiCH_t spi_hw_ch);
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param framef Frame format * @param framef Frame format
*/ */
void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef); void spiSetFrameFormat(
spiCH_t spi_hw_ch,
spi_framef_t framef);
/** /**
* @brief Get SPI frame format * @brief Get SPI frame format
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @return Frame format * @return Frame format
*/ */
spi_framef_t spiGetFrameFormat(spiCH_t spi_hw_ch); spi_framef_t spiGetFrameFormat(
spiCH_t spi_hw_ch);
/** /**
* @brief Set Clock Prescaler * @brief Set Clock Prescaler
@ -271,21 +299,26 @@ spi_framef_t spiGetFrameFormat(spiCH_t spi_hw_ch);
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param clkDiv * @param clkDiv
*/ */
void spiSetClockPrescaler(spiCH_t spi_hw_ch,uint32_t clkDiv); void spiSetClockPrescaler(
spiCH_t spi_hw_ch,
uint32_t clkDiv);
/** /**
* @brief Set communication Mode * @brief Set communication Mode
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param comMode * @param comMode
*/ */
void spiSetComMode(spiCH_t spi_hw_ch, spi_comMode_t comMode); void spiSetComMode(
spiCH_t spi_hw_ch,
spi_comMode_t comMode);
/** /**
* @brief Get Clock Prescaler * @brief Get Clock Prescaler
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @return prescaler * @return prescaler
*/ */
uint32_t spiGetClockPrescaler(spiCH_t spi_hw_ch); uint32_t spiGetClockPrescaler(
spiCH_t spi_hw_ch);
#if 0 #if 0
/** /**
@ -298,9 +331,11 @@ void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
/** /**
* @brief Enable software slave management * @brief Enable software slave management
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param logic Slave management done by software... 1 = enables / 0 = dissabledi * @param logic Slave management done by software... 1 = enables / 0 = dissabled
*/ */
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic); void spiSetSoftwareSlaveManagement(
spiCH_t spi_hw_ch,
uint8_t logic);
/** /**
@ -308,7 +343,9 @@ void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
* @param spi_hw_ch SPI hardware channel * @param spi_hw_ch SPI hardware channel
* @param logic 1 = enable / 0 = dissable * @param logic 1 = enable / 0 = dissable
*/ */
void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic); void spiSetInternalSlaveSelect(
spiCH_t spi_hw_ch,
uint8_t logic);
/*! /*!
* @brief Transmits and receives on byte of data * @brief Transmits and receives on byte of data
@ -316,7 +353,9 @@ void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic);
* @param tx_data 'tx_data' The byte to be transmitted" * @param tx_data 'tx_data' The byte to be transmitted"
* @return The received data * @return The received data
*/ */
uint8_t spiTrx(spiCH_t spi_hw_ch, uint8_t tx_data); uint8_t spiTrx(
spiCH_t spi_hw_ch,
uint8_t tx_data);
#ifdef __cplusplus #ifdef __cplusplus

@ -81,7 +81,7 @@ void spiDissable(spiCH_t spi_hw_ch)
void spiSetMode(spiCH_t spi_hw_ch, spi_mode_t mode) void spiSetMode(spiCH_t spi_hw_ch, spi_mode_t mode)
{ {
SPI_BASE->CR1 &= ~(mode << SPI_CR1_MSTR_Pos); SPI_BASE->CR1 &= ~(mode << SPI_CR1_MSTR_Pos);
SPI_BASE->CR1 |= (mode << SPI_CR1_MSTR_Pos); SPI_BASE->CR1 |= mode << SPI_CR1_MSTR_Pos;
} }
void spiSetPolarity(spiCH_t spi_hw_ch, spi_clkPol_t clkPol) void spiSetPolarity(spiCH_t spi_hw_ch, spi_clkPol_t clkPol)
@ -89,7 +89,7 @@ void spiSetPolarity(spiCH_t spi_hw_ch, spi_clkPol_t clkPol)
// reset // reset
SPI_BASE->CR1 &= ~SPI_CR1_CPOL; SPI_BASE->CR1 &= ~SPI_CR1_CPOL;
// set // set
SPI_BASE->CR1 |= (clkPol << SPI_CR1_CPOL_Pos); SPI_BASE->CR1 |= clkPol << SPI_CR1_CPOL_Pos;
} }
void spiSetPhase(spiCH_t spi_hw_ch, spi_phase_t phase) void spiSetPhase(spiCH_t spi_hw_ch, spi_phase_t phase)
@ -97,7 +97,7 @@ void spiSetPhase(spiCH_t spi_hw_ch, spi_phase_t phase)
// reset // reset
SPI_BASE->CR1 &= ~(phase << SPI_CR1_CPHA_Pos); SPI_BASE->CR1 &= ~(phase << SPI_CR1_CPHA_Pos);
// set // set
SPI_BASE->CR1 |= (phase << SPI_CR1_CPHA_Pos); SPI_BASE->CR1 |= phase << SPI_CR1_CPHA_Pos;
} }
void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef) void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef)
@ -105,7 +105,12 @@ void spiSetFrameFormat(spiCH_t spi_hw_ch, spi_framef_t framef)
// reset // reset
SPI_BASE->CR1 &= ~SPI_CR1_LSBFIRST; SPI_BASE->CR1 &= ~SPI_CR1_LSBFIRST;
// set // set
SPI_BASE->CR1 |= (framef << SPI_CR1_LSBFIRST_Pos); SPI_BASE->CR1 |= framef << SPI_CR1_LSBFIRST_Pos;
}
spi_framef_t spiGetFrameFormat(spiCH_t spi_hw_ch)
{
return (spi_framef_t)(SPI_BASE->CR1 & SPI_CR1_LSBFIRST) >> SPI_CR1_LSBFIRST_Pos;
} }
void spiSetClockPrescaler(spiCH_t spi_hw_ch, uint32_t clkDiv) void spiSetClockPrescaler(spiCH_t spi_hw_ch, uint32_t clkDiv)
@ -121,7 +126,7 @@ void spiSetComMode(spiCH_t spi_hw_ch, spi_comMode_t comMode)
// reset // reset
SPI_BASE->CR1 &= ~SPI_CR1_RXONLY; SPI_BASE->CR1 &= ~SPI_CR1_RXONLY;
// set // set
SPI_BASE->CR1 |= (comMode << SPI_CR1_RXONLY_Pos); SPI_BASE->CR1 |= comMode << SPI_CR1_RXONLY_Pos;
} }
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic) void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic)
@ -133,7 +138,7 @@ void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic)
} }
} }
void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic) void spiSetInternalSlaveSelect(spiCH_t spi_hw_ch, uint8_t logic)
{ {
SPI_BASE->CR1 &= ~SPI_CR1_SSI; SPI_BASE->CR1 &= ~SPI_CR1_SSI;
@ -147,12 +152,13 @@ uint8_t spiTrx(spiCH_t spi_hw_ch, uint8_t tx_data)
uint8_t data; uint8_t data;
// example // example
// wait for BSY bit to Reset -> This will indicate that SPI is not busy in communication // wait for BSY bit to Reset -> This will indicate that SPI is not busy in communication
while (((SPI1->SR)&(1<<7))); while (((SPI1->SR)&(1<<7)));
SPI1->DR = tx_data; // send data //SPI1->DR = tx_data; // send data
*(uint8_t*)&(SPI_BASE->DR) = tx_data;
// Wait for RXNE to set -> This will indicate that the Rx buffer is not empty // Wait for RXNE to set -> This will indicate that the Rx buffer is not empty
while (!((SPI1->SR) &(1<<0))); while (!((SPI1->SR) &(1<<0)));
data = SPI1->DR; data = SPI1->DR;

@ -9,6 +9,8 @@ void spiInitMaster(spiCH_t spi_hw_ch,
spi_comMode_t comMode, spi_comMode_t comMode,
uint32_t prescaler) uint32_t prescaler)
{ {
// TODO: step by step implementation
#if 0 #if 0
RCC->APB2ENR |= (1<<12); // Enable SPI1 CLock RCC->APB2ENR |= (1<<12); // Enable SPI1 CLock
@ -58,7 +60,7 @@ void spiInitMaster(spiCH_t spi_hw_ch,
//SPI1->CR1 |= (1<<8) | (1<<9); // SSM=1, SSi=1 -> Software Slave Management //SPI1->CR1 |= (1<<8) | (1<<9); // SSM=1, SSi=1 -> Software Slave Management
SPI_BASE->CR1 |= (1 << 8) | (1 << 9); SPI_BASE->CR1 |= (1 << 8) | (1 << 9);
spiSetSoftwareSlaveManagement(spi_hw_ch,1); //spiSetSoftwareSlaveManagement(spi_hw_ch,1);
@ -67,8 +69,10 @@ void spiInitMaster(spiCH_t spi_hw_ch,
//spiSetComMode(spi_hw_ch, comMode); //spiSetComMode(spi_hw_ch, comMode);
//SPI1->CR1 &= ~(1<<11); // CRCL =0, 8 bit data //SPI1->CR1 &= ~(1<<11); // CRCL =0, 8 bit data
SPI_BASE->CR1 &= ~(1 << 11); SPI_BASE->CR1 |= SPI_CR1_CRCL;
SPI_BASE->CR2 = SPI_CR2_SSOE | SPI_CR2_RXNEIE | SPI_CR2_FRXTH | SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2;
//spiDissable(spi_hw_ch); //spiDissable(spi_hw_ch);
#endif #endif
@ -201,7 +205,7 @@ void spiWrite16bit(spi_ch_t *spi_ch,
uint16_t bits) uint16_t bits)
{ {
pinWrite(spi_ch->pin,0); pinWrite(spi_ch->pin,0);
if(spi_ch->format == LSB_FIRST) { if(spiGetFrameFormat(spi_ch->spi) == SPI_MSB_FIRST) {
spiTrx(spi_ch->spi,(uint8_t)(bits >> 8)); spiTrx(spi_ch->spi,(uint8_t)(bits >> 8));
spiTrx(spi_ch->spi,(uint8_t)(bits)); spiTrx(spi_ch->spi,(uint8_t)(bits));
} else { } else {
@ -217,7 +221,7 @@ uint16_t spiReadWrite16bit(spi_ch_t *spi_ch,
uint16_t buf; uint16_t buf;
pinWrite(spi_ch->pin,0); pinWrite(spi_ch->pin,0);
if(spi_ch->format == LSB_FIRST) { if(spiGetFrameFormat(spi_ch->spi) == SPI_LSB_FIRST) {
buf = spiTrx(spi_ch->spi,(uint8_t)(bits >> 8)) << 8; buf = spiTrx(spi_ch->spi,(uint8_t)(bits >> 8)) << 8;
buf |= spiTrx(spi_ch->spi,(uint8_t)(bits)); buf |= spiTrx(spi_ch->spi,(uint8_t)(bits));
} else { } else {
@ -233,7 +237,8 @@ void spiWrite32bit(spi_ch_t *spi_ch,
uint32_t bits) uint32_t bits)
{ {
pinWrite(spi_ch->pin,0); pinWrite(spi_ch->pin,0);
if(spi_ch->format == LSB_FIRST) {
if(spiGetFrameFormat(spi_ch->spi) == SPI_LSB_FIRST) {
spiTrx(spi_ch->spi,(uint8_t)(bits >> 24)); spiTrx(spi_ch->spi,(uint8_t)(bits >> 24));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 16)); spiTrx(spi_ch->spi,(uint8_t)(bits >> 16));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 8)); spiTrx(spi_ch->spi,(uint8_t)(bits >> 8));
@ -253,7 +258,7 @@ uint32_t spiReadWrite32bit(spi_ch_t *spi_ch,
uint32_t buf; uint32_t buf;
pinWrite(spi_ch->pin,0); pinWrite(spi_ch->pin,0);
if(spi_ch->format == LSB_FIRST) { if(spiGetFrameFormat(spi_ch->spi) == SPI_LSB_FIRST) {
buf = spiTrx(spi_ch->spi,(uint8_t)(bits >> 24)) << 24; buf = spiTrx(spi_ch->spi,(uint8_t)(bits >> 24)) << 24;
buf |= spiTrx(spi_ch->spi,(uint8_t)(bits >> 16)) << 16; buf |= spiTrx(spi_ch->spi,(uint8_t)(bits >> 16)) << 16;
buf |= spiTrx(spi_ch->spi,(uint8_t)(bits >> 8)) << 8; buf |= spiTrx(spi_ch->spi,(uint8_t)(bits >> 8)) << 8;

@ -11,13 +11,36 @@ void max7219_test_display(spi_ch_t* spi_ch)
{ {
// set mode to display test // set mode to display test
spiWrite16bit(spi_ch, 0x0C01);
//delayMs(500); pinWrite(spi_ch->pin, 0);
spiWrite16bit(spi_ch, 0x0F00); spiTrx(spi_ch->spi, 0x0F);
delayMs(1); spiTrx(spi_ch->spi, 0x00);
pinWrite(spi_ch->pin,1);
//spiWrite16bit(spi_ch, 0x0C01);
//delayMs(50);
// spiWrite16bit(spi_ch, 0x0F01);
delayMs(1000);
pinWrite(spi_ch->pin, 0);
spiTrx(spi_ch->spi, 0x0C);
spiTrx(spi_ch->spi, 0x01);
pinWrite(spi_ch->pin,1);
// set mode to shutdown
// spiWrite16bit(spi_ch, 0x0C00);
delayMs(1000);
pinWrite(spi_ch->pin, 0);
spiTrx(spi_ch->spi, 0x0C);
spiTrx(spi_ch->spi, 0x00);
pinWrite(spi_ch->pin,1);
// set mode to shutdown // set mode to shutdown
spiWrite16bit(spi_ch, 0x0C00); // spiWrite16bit(spi_ch, 0x0C00);
//delayMs(500); delayMs(1000);
} }
void max7219_setIntensity(spi_ch_t* spi_ch, uint8_t intensity) void max7219_setIntensity(spi_ch_t* spi_ch, uint8_t intensity)
@ -80,9 +103,9 @@ int main(int argc, char *argv[])
pinSetAlternate(pinA7, 0); // SPI1_MOSI pinSetAlternate(pinA7, 0); // SPI1_MOSI
spiInitMaster(SPI_CH_1, spiInitMaster(SPI_CH_1,
NONINVERTED, SPI_NONINVERTED,
CAPTURE_ON_FIRST_CLK_TRANSITION, SPI_CAPTURE_ON_FIRST_CLK_TRANSITION,
MSB_FIRST, SPI_MSB_FIRST,
SPI_DOUPLEX, SPI_DOUPLEX,
7); 7);
@ -108,7 +131,6 @@ int main(int argc, char *argv[])
} }
while(1){ while(1){
//spiTrx(SPI_CH_1, 0xAE);
pinToggle(pinB3); pinToggle(pinB3);
max7219_test_display(&spi_test_channel); max7219_test_display(&spi_test_channel);
} }

@ -3,25 +3,9 @@
dir=$(pwd) dir=$(pwd)
echo $dir echo $dir
tmux new -s 'git' -d 'fish'
cd $dir/ked/ cd $dir/ked/
tmux new -s 'compile' -d 'fish' tmux -2 new -s 'compile' -d 'fish'
tmux new -s 'main' -d 'fish'
cd $dir/ked/csl/stm32f042/Src/
tmux new -s 'src' -d 'fish'
cd $dir/ked/csl/stm32f042/Device/ tmux -2 new -s 'workbench' -d 'fish'
tmux new -s 'device' -d 'fish'
cd $dir/ked/csl/interfaces/
tmux new -s 'interface' -d 'fish'
cd $dir/ked/
tmux new -s 'KED submodule' -d 'fish'
cd $dir/
tmux new -s 'miniCom' -d 'minicom'

Loading…
Cancel
Save