Esempio n. 1
0
/*
*	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();	
}
Esempio n. 2
0
	/**
  * @brief  Writes buffer of bytes to memory
	* @param address : address of the first byte
	* @param buff : pointer to a data buffer
	* @param size : number of bytes to write
  * @retval : None
  */	
	void ee_writeBuff(uint32_t address,uint8_t *buff,uint16_t size){
		uint16_t i;
			disableInterrupts();
		FLASH_Unlock(FLASH_MEMTYPE_DATA);
		for (i=0;i<size;i++){
			ee_write(address+i,buff[i]);				
		}	
			FLASH_Lock(FLASH_MEMTYPE_DATA);
		enableInterrupts();
	}
Esempio n. 3
0
/*
 * ee_write_short() - write a short (16 bit) data to EEPROM
 *
 * Data is stored in little endian format
 */
void ee_write_short(unsigned char addr, unsigned short data) {
	unsigned char byte_addr = addr;
	ee_write(byte_addr++, (unsigned char)data);
	ee_write(byte_addr, (unsigned char)(data>>8));
}