예제 #1
0
void FAST2420_WRITE_RAM_LE(TiSpiAdapter * spi,uint16 *p,uint16 a,uint8 c)
    {
    	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,(a >> 1) & 0xC0);
        for (n = 0; n < (c); n++) {
            spi_put(spi,((BYTE*)(p))[n]);
        }
        CC2420_SPI_DISABLE();
    }
예제 #2
0
static void enc_setbits_reg( unsigned char reg, unsigned char bits )
{
	// no automatic bank switching in this function !!!

	unsigned char addr = reg & ENC_REG_ADDR_MASK;

	enc_select();
	spi_put( ENC_SPI_OP_BFS | addr );
	spi_put( bits );
	enc_deselect();
}
예제 #3
0
void FAST2420_WRITE_RAM(TiSpiAdapter * spi,uint16 *p,uint16 a,uint8 c)
   {
   	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,(a >> 1) & 0xC0);
        n = c;
        do {
            spi_put(spi,((BYTE*)(p))[--n]);
        } while (n);
        CC2420_SPI_DISABLE();
    }
예제 #4
0
void gotoXY(LCD *lcd, char x, char y){
	pin_low(lcd->enb);
	pin_low(lcd->mode);

	spi_put( 0x80 | x );
	_delay_us(100);
	spi_put( 0x40 | y );
	_delay_us(100);


	pin_high(lcd->enb);
	pin_high(lcd->mode);
}
예제 #5
0
void write_buffer(LCD *lcd){
	gotoXY(lcd,0,0);//ensure at starting point
	for(int i = 0; i < 14*6; i++){
		int c = (int)circular_buffer_get_index(lcd->buffer,i);
		if(c < 32) c = ' ';
		c-=32;
		for(int i = 0; i < 5; i++){
			spi_put(ASCII[c][i]);
			_delay_us(100);
		}
		spi_put(0x00);
		_delay_us(100);
	}	
}
예제 #6
0
/**
 * \brief Interrupt callback for SPI interrupt
 *  \param none
 */
static void spi_interrupt_callback(void)
{
	uint8_t data = spi_get(SPI_SLAVE_EXAMPLE);

	if (data_transfer == true) {
		spi_put(SPI_SLAVE_EXAMPLE, data_slave_tx[count++]);
	} else {
		data_slave_rx[count++] = data;
		if (data_slave_rx[0] == SLAVE_RD_CMD) {
			data_transfer = true;
			count = 0;
			spi_put(SPI_SLAVE_EXAMPLE, data_slave_tx[count++]);
		}
	}
}
예제 #7
0
void clear_screen(LCD *lcd){
	for(int i = 0; i < 14*6*6; i++){
		spi_put(0x00);
		_delay_us(100);
	}

}
예제 #8
0
/*! \brief Sets the number of filter taps of the IMU internal low pass filter.

	\details 
*/
void low_pass_filter_setting(uint8_t nr_filter_taps){
	uint8_t log2_nr_filter_taps = nr_filter_taps;
	if (log2_nr_filter_taps>MAX_LOG2_NR_FILTER_TAPS){
		log2_nr_filter_taps=MAX_LOG2_NR_FILTER_TAPS;}
	uint16_t tx_word = log2_nr_filter_taps + (1<<8)*SET_NR_FILTER_TAPS;
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,tx_word);
}
예제 #9
0
void fill(byte color) {
int b, i;
	for (b=0; b < numboards; b++) {
		if (b) delay(INTER_BOARD_DELAY);
		spi_start();
		for (i = 0; i < 64; i++) spi_put(color);
		spi_end();
	}
}
예제 #10
0
/*static inline*/ void enc_reset(void)
{
	enc_select();
	spi_put( ENC_SPI_OP_SC );
	enc_deselect();

	// errata #2: wait for at least 300 us
	usdelay( 1000 );
}
예제 #11
0
static inline void enc_reset(void)
{
	enc_select();
	spi_put( ENC_SPI_OP_SC );
	enc_deselect();

	// errata #2: wait for at least 300 us
	_delay_ms(1);
}
예제 #12
0
파일: hal_spi.c 프로젝트: gxp/node
uint8 spi_write(TiSpiAdapter * spi,  char * buf, uint8 len, uint8 opt )
{
	uint8 n = 0;
    for (n = 0; n < len; n++) 
	{ 
		spi_put(spi,((BYTE*)(buf))[n]); 
	} 
      
    return 0;
}
예제 #13
0
void FAST2420_WRITE_FIFO(TiSpiAdapter * spi,uint8 *p,uint8 c)
    {
        uint8 n = 0;
        CC2420_SPI_ENABLE();
        FAST2420_TX_ADDR(spi,CC2420_TXFIFO);
        for (n = 0; n < (c); n++) {
            spi_put(spi,((BYTE*)(p))[n]);
        }
        CC2420_SPI_DISABLE();
    }
예제 #14
0
void FAST2420_READ_RAM_LE(TiSpiAdapter * spi,uint8 *p,uint16 a,uint8 c)
   {
   	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,((a >> 1) & 0xC0) | 0x20);
        for (n = 0; n < (c); n++) {
            spi_get(spi,(char*)(p + n));
        }
        CC2420_SPI_DISABLE();
    }
예제 #15
0
char SPI_L(char TX_Data) 
{	
/* Send pattern. */
	spi_put(&NRF24L01_L_SPI,TX_Data);

	/* Wait for transmission complete. */
	while(!(spi_is_tx_ok(&NRF24L01_L_SPI)));
	/* Read received data. */
	uint8_t result = spi_get(&NRF24L01_L_SPI);

	return(result);
}
예제 #16
0
void FAST2420_READ_RAM(TiSpiAdapter * spi,uint8 *p,uint16 a,uint8 c)
    {
    	uint8 n;
        CC2420_SPI_ENABLE();
        spi_put(spi,0x80 | (a & 0x7F));
        spi_put(spi,((a >> 1) & 0xC0) | 0x20);
        n = c;
        do {
            spi_get(spi,(char*)(p + (--n)));
        } while (n);
        CC2420_SPI_DISABLE();
    }
예제 #17
0
void scrolling(void) {
	snooze(scrolldelay);
	uint8_t board_offset;
	for (board_offset = 0; board_offset < (8*numboards); board_offset = board_offset + 8) {
		if (board_offset) delay(10);			// interframe delay, per data sheet
		spi_start();
		uint8_t r;
		for (r=0; r < 8; r++) {
			//produce all the columns of one row
			int o = ho;						// start with the global offset
			char *txt = t;	
			uint8_t w = getCharWidth(*txt);
			uint8_t b = getCharData(*txt, r, ho);
			uint8_t c = 0; 
			while (c < (board_offset + 8)) {
				if (o <= w) {		 // any bits left?
					if (c >= board_offset) {
						spi_put((b & 0x80) ? fgcolor : bgcolor);
					}
					c++;			// next column
					o++;			// ... using next bit of this one
					b = (b << 1);		// ...teed up right here
				} else {			 // advance to next char
					if (*txt) ++txt;
					w = getCharWidth(*txt);
					b = getCharData(*txt, r, 0);
					o = 0;
				}
			}
		}
		spi_end();
	}

	// update offset and char for next frame
	if (++ho > getCharWidth(*t)) {
		ho = 0;
		if (*t) ++t;		// on to the next char
	}

	if (!(*t)) {
		snooze(0);	// cancel the iso-snooze above
		set_state(dwell);
	}
}
예제 #18
0
LCD* lcd_new(Pin *mode, Pin *reset, Pin *enable){
        LCD *lcd = (LCD * ) malloc( sizeof( LCD ) );

	lcd->spi = spi_init();
	lcd->mode = mode;
	lcd->rst = reset;
	lcd->enb = enable;
	lcd->col = 14;
	lcd->row = 6;
	lcd->cursor = 0;
	lcd->buffer = circular_buffer_new(128);

	pin_config_out(mode);
	pin_config_out(reset);
	pin_config_out(enable);

	pin_low(enable);

	//active low reset pulse
	pin_high(reset);
	pin_pulse(reset);

	//enter config mode
	pin_low(mode);

	//config lcd driver
	_delay_us(100);
	spi_put(0x21);
	_delay_us(100);
	spi_put(0xA0);
	_delay_us(100);
	spi_put(0x04);
	_delay_us(100);
	spi_put(0x14);
	_delay_us(100);
	spi_put(0x20);
	_delay_us(100);
	spi_put(0x0C);
	_delay_us(100);

	pin_high(mode);
	clear_screen(lcd);
	
	//ready to accept data
	gotoXY(lcd,0,0);

	pin_high(enable);
	return lcd;
}
예제 #19
0
/*! \brief Request and reads all sensor output data from IMU.

	\details This function uses the IMU burst read functionallity in which all
	IMU sensor data (rotation, specific force, temperature, and supply voltage)
	is output by the IMU after a single request. This way only two clock
	cycles are required between each read operation. This is faster than only
	reading out rotation and specific force.
	The functions first reads in the values in 16-bit intermediate variables
	and then call the help functions convert_inert_readings() and
	convert_auxiliary_data() to shift out status bits and scale to SI units.
	
	@param[out] angular_rates_in		Vector containing the 3 (x,y,z) angular rates in [rad/sec].
	@param[out] accelerations_in		Vector containing the 3 (x,y,z) specific force in [m/s^2].
	@param[out] imu_temperatures		Vector containing the 3 (x,y,z) temperatur readings in [C].
	@param[out] imu_supply_voltage		Supply voltage measurement in [V].
*/
void imu_burst_read(void){
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,BURST_READ);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	supply = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	xgyro = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	ygyro = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	zgyro = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	xacc = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	yacc = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	zacc = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	xtemp = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	ytemp = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	ztemp = spi_get(SPI_IMU);
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,CONFIG_SPI_MASTER_DUMMY);
	while (!spi_is_rx_ready(SPI_IMU)) {;}
	aux_adc = spi_get(SPI_IMU);
	
	convert_inert_readings();
	convert_auxiliary_data();
}
예제 #20
0
/*! \brief Initializes the internal IMU gyro calibration routine.

	\details The internal gyro calibration routine will take the mean gyro
	value over approx. 15s. During this time the IMU will be off-line (not
	sending out any	interrupts). During this period the IMU should be kept
	statinarry.
*/
void precision_gyro_bias_null_calibration(void){
	while (!spi_is_tx_ready(SPI_IMU)) {;}
	spi_put(SPI_IMU,PRECISION_GYRO_BIAS_CALIBRATION);
	// After this the IMU will be off-line for ~15s
}
예제 #21
0
int main(void)
{
	sysclk_init();

	int i=0;

	// board_init();

	sysclk_enable_pba_module(SYSCLK_SPI);

	// spi_reset(SPI_EXAMPLE);
	// spi_set_master_mode(SPI_EXAMPLE);
	// spi_disable_modfault(SPI_EXAMPLE);
	// spi_disable_loopback(SPI_EXAMPLE);
	// spi_set_chipselect(SPI_EXAMPLE,(1 << AVR32_SPI_MR_PCS_SIZE) - 1);
	// spi_disable_variable_chipselect(SPI_EXAMPLE);
	// spi_disable_chipselect_decoding(SPI_EXAMPLE);
	// spi_set_delay(SPI_EXAMPLE,0);

	// spi_set_chipselect_delay_bct(SPI_EXAMPLE,0,0);
	// spi_set_chipselect_delay_bs(SPI_EXAMPLE,0,0);
	// spi_set_bits_per_transfer(SPI_EXAMPLE,0, 8);
	// spi_set_baudrate_register(SPI_EXAMPLE,0, getBaudDiv(1000000, sysclk_get_peripheral_bus_hz(SPI_EXAMPLE)));
	// spi_enable_active_mode(SPI_EXAMPLE,0);
	// spi_set_mode(SPI_EXAMPLE,0,SPI_MODE_0);

	  static const gpio_map_t SPI_GPIO_MAP = {
    {AT45DBX_SPI_SCK_PIN,  AT45DBX_SPI_SCK_FUNCTION },
    {AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION},
    {AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION},
    {AT45DBX_SPI_NPCS0_PIN,  AT45DBX_SPI_NPCS0_FUNCTION },
    // {AT45DBX_SPI_NPCS1_PIN,  AT45DBX_SPI_NPCS1_FUNCTION },
  };

  // Assign GPIO to SPI.
  gpio_enable_module(SPI_GPIO_MAP, sizeof(SPI_GPIO_MAP) / sizeof(SPI_GPIO_MAP[0]));

  spi_options_t spiOptions = {
    .reg = 0,
    .baudrate = 1000000,
    .bits = 8,
    .trans_delay = 0,
    .spck_delay = 0,
    .stay_act = 1,
    .spi_mode = 0,
    .modfdis = 1
  };


  // Initialize as master.
  spi_initMaster(SPI_EXAMPLE, &spiOptions);
  // Set SPI selection mode: variable_ps, pcs_decode, delay.
  spi_selectionMode(SPI_EXAMPLE, 0, 0, 0);
  // Enable SPI module.
  spi_enable(SPI_EXAMPLE);

  // spi_setupChipReg( SPI, &spiOptions, FPBA_HZ );
  spi_setupChipReg(SPI_EXAMPLE, &spiOptions, sysclk_get_pba_hz() );

	spi_enable(SPI_EXAMPLE);


	while (true)
	{
		i++;
		delay_ms(10);
			// status = spi_at45dbx_mem_check();
		spi_selectChip(SPI_EXAMPLE,0);
		spi_put(SPI_EXAMPLE,i);
		spi_unselectChip(SPI_EXAMPLE,0);

	}
}
예제 #22
0
파일: hal_spi.c 프로젝트: gxp/node
// @TODO
// obsolete functions
// will be eliminated soon
//
void FASTSPI_TX_WORD_LE(TiSpiAdapter * spi, uint16 x) 
    { 
        spi_put(spi,x); 
        spi_put(spi,(x) >> 8); 
    }