Untitled
unknown
plain_text
3 years ago
2.8 kB
3
Indexable
#include "stdint.h" sbit Chip_Select_MB1 at GPIOA_ODR.B4; sbit Chip_Select_MB2 at GPIOB_ODR.B2; const uint32_t _SRAM_24BIT_DATA = 0x00FFFFFF; // SRAM click has 24bit address space const uint8_t _SRAM_WRITE = 0x02; // select writing operation const uint8_t _SRAM_READ = 0x03; // select writing operation uint32_t regAddress = 0; // set desired address in memory space uint8_t regValue = 0xAA; // set desired value in memory space void main() { GPIO_Digital_Output(&GPIOA_BASE, _GPIO_PINMASK_4); // MB1 CS Chip_Select_MB1 = 1; // De-select SRAM click GPIO_Digital_Output(&GPIOB_BASE, _GPIO_PINMASK_2); // MB2 CS Chip_Select_MB2 = 1; // De-select 8x8 click GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_LOW);// Display on PORTE GPIOE_ODR = 0; // Clear value /* Initialize SPI*/ SPI1_Init_Advanced( _SPI_FPCLK_DIV64, _SPI_MASTER | _SPI_8_BIT | _SPI_CLK_IDLE_LOW | _SPI_FIRST_CLK_EDGE_TRANSITION | _SPI_MSB_FIRST | _SPI_SS_DISABLE | _SPI_SSM_ENABLE | _SPI_SSI_1, &_GPIO_MODULE_SPI1_PA56_PB5); Delay_10ms(); // small delay regAddress &= _SRAM_24BIT_DATA; // convert address into SRAM click memory space Chip_Select_MB1 = 0; // set CS line to logical high (select device) SPI1_Write(_SRAM_WRITE); // send notification of pending write to memory SPI1_Write(( uint8_t ) ( regAddress >> 16 )); // first byte of address 1/3 SPI1_Write(( uint8_t ) ( regAddress >> 8 )); // second byte of address 2/3 SPI1_Write(( uint8_t ) regAddress); // third byte of address 3/3 SPI1_Write(regValue); // send value to be written into memory Chip_Select_MB1 = 1; // deselect device (write portion finished) Chip_Select_MB1 = 0; // select device again SPI1_Write(_SRAM_READ); // send notification of pending read from memory SPI1_Write(( uint8_t ) ( regAddress >> 16 )); // first byte of address 1/3 SPI1_Write(( uint8_t ) ( regAddress >> 8 )); // second byte of address 2/3 SPI1_Write(( uint8_t ) regAddress); // third byte of address 3/3 GPIOE_ODR = SPI1_Read(0); // read value from memory and display on PORTE LEDs Chip_Select_MB1 = 1; // deselect device (read portion finished) }
Editor is loading...