/* * Function: spi_test * Description: be used to test SPI related functions by using the AT450BXX module * * host slave * MISO < - > MISO * MOSI < - > MOSI * CLK < - > CLK * CE0/1 < - > CS */ void spi_test(void) { int num; unsigned char wBuf = 0x3f; unsigned char rBuf; printf("--------------->Test SPI With AT450BXX<--------------\n"); bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64); //bcm2835_spi_chipSelect(BCM2835_SPI_CS0); //bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, HIGH); bcm2835_gpio_fsel(PIN_CS, BCM2835_GPIO_FSEL_OUTP); /*set CS, and must be called*/ printf("SPI write 0x%x\n", wBuf); ee_write(0,wBuf); bcm2835_delay(50); rBuf = ee_read(0); printf("SPI read 0x%x\n", rBuf); if(wBuf == rBuf) { printf("SPI interface work well !...\n"); } else { printf("SPI interface work bad !...\n"); } bcm2835_spi_end(); }
/** * @brief Reads buffer of bytes from memory * @param address : address of the first byte * @param buff : pointer to a data buffer * @param size : number of bytes to read * @retval : None */ void ee_readBuff(uint32_t address,uint8_t *buff,uint16_t size){ uint16_t i; disableInterrupts(); FLASH_Unlock(FLASH_MEMTYPE_DATA); for (i=0;i<size;i++){ buff[i]=ee_read(address+i); } FLASH_Lock(FLASH_MEMTYPE_DATA); enableInterrupts(); }
/* * ee_read_short() - read a short (16 bit) word from EEPROM * * Data is stored in little endian format */ unsigned short ee_read_short(unsigned char addr) { unsigned char byte_addr = addr; unsigned short ret = ee_read(byte_addr++); ret = ret | ((unsigned short)ee_read(byte_addr) << 8); return ret; }