//-------------------------------------------------------// // Project Code : V2H6K01-ENEMAN-CPU1 // File Name : EepromLib.h // Created on : 2023. 07. 12. // Description : // Author : KWONJEONGMIN // Last modified Date : //-------------------------------------------------------// #include "CommonLib.h" #include "F2837xD_gpio.h" // // Calculate BRR: 7-bit baud rate register value // SPI CLK freq = 500 kHz // LSPCLK freq = CPU freq / 4 (by default) // BRR = (LSPCLK freq / SPI CLK freq) - 1 // #define CPUCLK 200000000L // CPU Main Clock #define SPI_BRR ((200E6 / 4) / 500E3) - 1 // SPI BRR //void InitSpi(void) //{ // //Initialize SPI-C // // // Set reset low before configuration changes // // Clock polarity (0 == rising, 1 == falling) // // 16-bit character // // Enable loop-back // SpicRegs.SPICCR.bit.SPISWRESET = 0; // SpicRegs.SPICCR.bit.CLKPOLARITY = 0; // SpicRegs.SPICCR.bit.SPICHAR = (16-1); // SpicRegs.SPICCR.bit.SPILBK = 1; // // // Enable master (0 == slave, 1 == master) // // Enable transmission (Talk) // // Clock phase (0 == normal, 1 == delayed) // // SPI interrupts are enabled // SpicRegs.SPICTL.bit.MASTER_SLAVE = 1; // SpicRegs.SPICTL.bit.TALK = 1; // SpicRegs.SPICTL.bit.CLK_PHASE = 0; // SpicRegs.SPICTL.bit.SPIINTENA = 1; // // // Set the baud rate // SpicRegs.SPIBRR.bit.SPI_BIT_RATE = SPI_BRR; // // // Set FREE bit // // Halting on a breakpoint will not halt the SPI // SpicRegs.SPIPRI.bit.FREE = 1; // // // Release the SPI from reset // SpicRegs.SPICCR.bit.SPISWRESET = 1; //} // // InitSpiGpio - This function initializes GPIO pins to function as SPI pins. // Each GPIO pin can be configured as a GPIO pin or up to 3 // different peripheral functional pins. By default all pins come // up as GPIO inputs after reset. // // Caution: // For each SPI peripheral // Only one GPIO pin should be enabled for SPISOMO operation. // Only one GPIO pin should be enabled for SPISOMI operation. // Only one GPIO pin should be enabled for SPICLK operation. // #ifdef CPU1 void InitSpiGpio(void) { EALLOW; // // Enable internal pull-up for the selected pins // // Pull-ups can be enabled or disabled by the user. // This will enable the pull ups for the specified pins. // GpioCtrlRegs.GPDPUD.bit.GPIO100 = 0; // Enable pull-up on GPIO100 (SPISIMOC) GpioCtrlRegs.GPDPUD.bit.GPIO101 = 0; // Enable pull-up on GPIO101 (SPISOMIC) GpioCtrlRegs.GPDPUD.bit.GPIO102 = 0; // Enable pull-up on GPIO101 (SPICLKC) // // Set qualification for selected pins to asynch only // // This will select asynch (no qualification) for the selected pins. // GpioCtrlRegs.GPDQSEL1.bit.GPIO100 = 3; //Asynch input GPIO100 (SPISIMOC) GpioCtrlRegs.GPDQSEL1.bit.GPIO101 = 3; //Asynch input GPIO101 (SPISOMIC) GpioCtrlRegs.GPDQSEL1.bit.GPIO102 = 3; //Asynch input GPIO101 (SPICLKC) // //Configure SPI-A pins using GPIO regs // // This specifies which of the possible GPIO pins will be SPI functional pins. // GpioCtrlRegs.GPDMUX1.bit.GPIO100 = 1; //Configure GPIO100 as SPISIMOC GpioCtrlRegs.GPDMUX1.bit.GPIO101 = 1; //Configure GPIO101 as SPISOMIC GpioCtrlRegs.GPDMUX1.bit.GPIO102 = 1; //Configure GPIO102 as SPICLKC EDIS; } #endif void ew_disable() { } void ew_enable() { } void is_ew_enabled() { } void erase_all() { } void write_all() { } void write() { } void erase() { } void read() { }