working on init function

pull/2/head
polymurph 3 years ago
parent bcff2e2cc0
commit f678c41563

@ -75,7 +75,6 @@ typedef uint8_t (*readReg_t) (uint8_t);
* @param spi_hw_ch SPI hardware channel
*/
void spiInitMaster(spiCH_t spi_hw_ch,
spi_mode_t mode,
spi_clkPol_t clockPolarity,
spi_phase_t phase,
spi_framef_t frameFormat,
@ -296,6 +295,21 @@ uint32_t spiGetClockPrescaler(spiCH_t spi_hw_ch);
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
#endif
/**
* @brief Enable software slave management
* @param spi_hw_ch SPI hardware channel
* @param logic Slave management done by software... 1 = enables / 0 = dissabledi
*/
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic);
/**
* @brief Enable internal slave select
* @param spi_hw_ch SPI hardware channel
* @param logic 1 = enable / 0 = dissable
*/
void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic);
/*!
* @brief Transmits and receives on byte of data
* @param spi_hw_ch SPI hardware channel

@ -113,7 +113,7 @@ void spiSetClockPrescaler(spiCH_t spi_hw_ch, uint32_t clkDiv)
// reset
SPI_BASE->CR1 &= ~SPI_CR1_BR;
// set
SPI_BASE->CR1 |= clkDiv & SPI_CR1_BR;
SPI_BASE->CR1 |= (clkDiv << SPI_CR1_BR_Pos) & SPI_CR1_BR;
}
void spiSetComMode(spiCH_t spi_hw_ch, spi_comMode_t comMode)
@ -124,6 +124,24 @@ void spiSetComMode(spiCH_t spi_hw_ch, spi_comMode_t comMode)
SPI_BASE->CR1 |= (comMode << SPI_CR1_RXONLY_Pos);
}
void spiSetSoftwareSlaveManagement(spiCH_t spi_hw_ch, uint8_t logic)
{
SPI_BASE->CR1 &= ~SPI_CR1_SSM;
if(logic){
SPI_BASE->CR1 |= SPI_CR1_SSM;
}
}
void spiSetInternalSlaveSelect(spiCH_tspi_hw_ch, uint8_t logic)
{
SPI_BASE->CR1 &= ~SPI_CR1_SSI;
if(logic) {
SPI_BASE->CR1 |= SPI_CR1_SSI;
}
}
uint8_t spiTrx(spiCH_t spi_hw_ch, uint8_t tx_data)
{
uint8_t data;

@ -3,38 +3,78 @@
// generic implementation of spi channel class
void spiInitMaster(spiCH_t spi_hw_ch,
spi_mode_t mode,
spi_clkPol_t clockPolarity,
spi_phase_t phase,
spi_framef_t frameFormat,
spi_comMode_t comMode,
uint32_t prescaler)
{
#if 0
RCC->APB2ENR |= (1<<12); // Enable SPI1 CLock
SPI1->CR1 |= (1<<0)|(1<<1); // CPOL=1, CPHA=1
//SPI_BASE->CR1 |= (1<<0) | (1 << 1);
SPI1->CR1 |= (1<<2); // Master Mode
//SPI_BASE->CR1 |= (1 << 2);
SPI1->CR1 |= (3<<3); // BR[2:0] = 011: fPCLK/16, PCLK2 = 80MHz, SPI clk = 5MHz
//SPI_BASE-> CR1 |= (3<<3);
SPI1->CR1 &= ~(1<<7); // LSBFIRST = 0, MSB first
//SPI_BASE->CR1 &= ~(1<<7);
SPI1->CR1 |= (1<<8) | (1<<9); // SSM=1, SSi=1 -> Software Slave Management
//SPI_BASE->CR1 |= (1 << 8) | (1 << 9);
SPI1->CR1 &= ~(1<<10); // RXONLY = 0, full-duplex
//SPI_BASE->CR1 &= ~(1<<10);
SPI1->CR1 &= ~(1<<11); // CRCL =0, 8 bit data
//SPI_BASE->CR1 &= ~(1 << 11);
#endif
#if 1
//RCC->APB2ENR |= (1<<12); // Enable SPI1 CLock
spiEnableBus(spi_hw_ch);
//SPI1->CR1 |= (1<<0)|(1<<1); // CPOL=1, CPHA=1
SPI_BASE->CR1 |= (1<<2) | (1 << 1);
//SPI_BASE->CR1 |= (1<<0) | (1 << 1);
spiSetPolarity(spi_hw_ch,clockPolarity);
spiSetPhase(spi_hw_ch,phase);
//SPI1->CR1 |= (1<<2); // Master Mode
SPI_BASE->CR1 |= (1 << 2);
//SPI_BASE->CR1 |= (1 << 2);
spiSetMode(spi_hw_ch, SPI_MASTER);
//SPI1->CR1 |= (3<<3); // BR[2:0] = 011: fPCLK/16, PCLK2 = 80MHz, SPI clk = 5MHz
SPI_BASE-> CR1 |= (3<<3);
//SPI_BASE-> CR1 |= (3<<3);
spiSetClockPrescaler(spi_hw_ch, prescaler);
//SPI1->CR1 &= ~(1<<7); // LSBFIRST = 0, MSB first
SPI_BASE->CR1 &= ~(1<<7);
//SPI_BASE->CR1 &= ~(1<<7);
spiSetFrameFormat(spi_hw_ch,frameFormat);
//SPI1->CR1 |= (1<<8) | (1<<9); // SSM=1, SSi=1 -> Software Slave Management
SPI_BASE->CR1 |= (1 << 8) | (1 << 9);
spiSetSoftwareSlaveManagement(spi_hw_ch,1);
//SPI1->CR1 &= ~(1<<10); // RXONLY = 0, full-duplex
SPI_BASE->CR1 &= ~(1<<10);
//spiSetComMode(spi_hw_ch, comMode);
//SPI1->CR1 &= ~(1<<11); // DFF=0, 8 bit data
//SPI1->CR1 &= ~(1<<11); // CRCL =0, 8 bit data
SPI_BASE->CR1 &= ~(1 << 11);
//spiDissable(spi_hw_ch);
#endif
//SPI1->CR2 = 0;
SPI_BASE->CR2 = 0;
//SPI_BASE->CR2 = 0;
/*
spiReset(spi_ch);
@ -51,7 +91,7 @@ void spiInitMaster(spiCH_t spi_hw_ch,
spiSetClockPrescaler(spi_ch, prescaler);
spiDissable(spi_ch);
spiDissable(spi_hw_ch);
*/
}
@ -194,7 +234,7 @@ void spiWrite32bit(spi_ch_t *spi_ch,
{
pinWrite(spi_ch->pin,0);
if(spi_ch->format == LSB_FIRST) {
spiTrx(spi_ch->spi,(uint8_t)(bits >> 32));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 24));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 16));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 8));
spiTrx(spi_ch->spi,(uint8_t)(bits));
@ -202,7 +242,7 @@ void spiWrite32bit(spi_ch_t *spi_ch,
spiTrx(spi_ch->spi,(uint8_t)(bits));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 8));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 16));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 32));
spiTrx(spi_ch->spi,(uint8_t)(bits >> 24));
}
pinWrite(spi_ch->pin,1);
}

@ -10,10 +10,14 @@
void max7219_test_display(spi_ch_t* spi_ch)
{
// set mode to display test
spiWrite16bit(spi_ch, 0xFFFF);
delayMs(10000);
spiWrite16bit(spi_ch, 0x0C01);
//delayMs(500);
spiWrite16bit(spi_ch, 0x0F00);
delayMs(1);
// set mode to shutdown
spiWrite16bit(spi_ch, 0x0C00);
//delayMs(500);
}
void max7219_setIntensity(spi_ch_t* spi_ch, uint8_t intensity)
@ -76,11 +80,11 @@ int main(int argc, char *argv[])
pinSetAlternate(pinA7, 0); // SPI1_MOSI
spiInitMaster(SPI_CH_1,
SPI_MASTER,
NONINVERTED,
CAPTURE_ON_FIRST_CLK_TRANSITION,
MSB_FIRST,
0b111);
SPI_DOUPLEX,
7);
spiSetupCH(&spi_test_channel, SPI_CH_1, pinA4);
@ -104,9 +108,9 @@ int main(int argc, char *argv[])
}
while(1){
spiTrx(SPI_CH_1, 0xAE);
//spiTrx(SPI_CH_1, 0xAE);
pinToggle(pinB3);
//max7219_test_display(&spi_test_channel);
max7219_test_display(&spi_test_channel);
}
for(i = 0 ; i < 100 ; i++) {

Loading…
Cancel
Save