/*
	Name: spi_transmit
	Description: Send data over SPI, and receive at the same time. Received data is put into transmitted data buffer.
	Parameters:
		1. devsel : int - selects which device to communicate - 0=touch panel , 1=lcd
		2. data : pointer(array) uint8_t - data to be sent, and buffer for data to be received
		3. len : int - bytes count to be sent from buffeer
	Returns:
		0 - on success, negative - fail, see function content for error return values. Also check errno for more information.
		positive - number of bytes received
		
*/
int spi_transmit(int devsel, uint8_t *data, int len) {

	if (devsel == 0) {
		bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
		#ifdef _DEBUG_
			fprintf(stdout, "spi_transmit.CS=CS0 , ");
		#endif
	} else {
		bcm2835_spi_chipSelect(BCM2835_SPI_CS1);
		#ifdef _DEBUG_
			fprintf(stdout, "spi_transmit.CS=CS1 , ");
		#endif
	}
	
	#ifdef _DEBUG_
		fprintf(stdout, "data[%i]=",len);
		for(int i=0;i<len;i++) {
			uint8_t t = *(data+i);
			fprintf(stdout,"%02X ",t);
		}
		fprintf(stdout, "\n");
	#endif

	
	bcm2835_spi_transfern((char*)data, len);
	
	return len;
}
Ejemplo n.º 2
0
char MPU9250::WriteReg( uint8_t WriteAddr,char WriteData )
{
  unsigned int recieved;

  char buff[2];
  buff[0] = WriteAddr;
  buff[1] = WriteData;
  bcm2835_spi_chipSelect(MPU9250_PIN);                      // The default
  bcm2835_spi_transfern(buff,2);
  bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);
  return buff[1];
}
Ejemplo n.º 3
0
void VM205::connect() {
	bcm2835_spi_begin();
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE2);
	bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
	bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
	bcm2835_spi_setClockDivider(500);
}
Ejemplo n.º 4
0
void SPIClass::chipSelect(int csn_pin) {
	if (csn_pin == RPI_GPIO_P1_26) csn_pin = BCM2835_SPI_CS1;
	else if (csn_pin == RPI_GPIO_P1_24) csn_pin = BCM2835_SPI_CS0;
	else csn_pin = BCM2835_SPI_CS0;
	bcm2835_spi_chipSelect(csn_pin);
	delayMicroseconds(5);
}
Ejemplo n.º 5
0
int main(int argc, char **argv) {
	if (!bcm2835_init())
		return 1;
	bcm2835_spi_begin();
	bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE1);
	bcm2835_spi_setClockDivider(2170-200);
	bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
	bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);
	
	volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4;
	bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_LEN, BCM2835_SPI0_CS_LEN); //make it 9 bit
	
	volatile uint32_t* ltoh = bcm2835_spi0+BCM2835_SPI0_LTOH/4;
	bcm2835_peri_set_bits(ltoh,0b1111,0);
	
	unsigned int i='a';
	
	while(1) {
		for(char c='a';c<='z';c++) {
			spi_uart_tx(c);
			spi_uart_tx(' ');
		}
		spi_uart_tx('\n');
		
// 		bcm2835_delay(10);
// 		printf(" ");
	}
	
	bcm2835_spi_end();
	bcm2835_close();
	
	return 0;
}
Ejemplo n.º 6
0
void Rf24RaspberryPiIo::select() {
    bcm2835_spi_setBitOrder(RF24_BIT_ORDER);
    bcm2835_spi_setDataMode(RF24_DATA_MODE);
    bcm2835_spi_setClockDivider(spi_speed ? spi_speed : RF24_CLOCK_DIVIDER);
    bcm2835_spi_chipSelect(csn_pin);
    delayMicroseconds(5);
}
Ejemplo n.º 7
0
void d8x8matrix_write(const device_info_t *device_info, const char *buf, uint8_t nbyte) {
	char c;
	uint8_t i;
	int j, k;

	if (nbyte > device_info->internal.count) {
		nbyte = device_info->internal.count;
	}

	for (i = 1; i < 9; i++) {
		k = (int) nbyte;

		for (j = 0; j < ((int) device_info->internal.count * 2) - ((int) nbyte * 2); j = j + 2) {
			spi_data[j] = MAX7219_REG_NOOP;
			spi_data[j + 1] = 0;
		}

		while (--k >= 0) {
			c = buf[k];
			spi_data[j++] = i;
			spi_data[j++] = rotate((uint8_t) c, 8 - i);
		}

		if (device_info->chip_select == SPI_CS2) {
			bcm2835_aux_spi_setClockDivider(device_info->internal.clk_div);
			bcm2835_aux_spi_writenb((const char *) spi_data, (uint32_t) j);
		} else {
			bcm2835_spi_setClockDivider(device_info->internal.clk_div);
			bcm2835_spi_chipSelect(device_info->chip_select);
			bcm2835_spi_writenb((const char *) spi_data, (uint32_t) j);
		}
	}
}
Ejemplo n.º 8
0
SpiPlateformImplementation::SpiPlateformImplementation( SpiChipSelect cs):
_cs( cs )
{
    if( s_count++ == 0)
    {
        printf("\n SPI INIT");
#ifdef TARGET_RASPBERRY_PI
        bcm2835_spi_begin();
        
        bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
        bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
        bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_4096);
        bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
        bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);
#endif
        /*
        setBitOrder( SpiMSB );
        setDataMode( SpiMode_0);
        setClockDivider( SPI_CLOCK_DIVIDER_4096);
        setChipSelect( _cs );
        setCsPolarity( low );
         */
    }


}
Ejemplo n.º 9
0
void MPU9250::ReadRegs( uint8_t ReadAddr, char *ReadBuf, unsigned int Bytes )
{

  char buff[1+Bytes];
  buff[0] = ReadAddr | READ_FLAG;
  for(int i = 1; i < 1+Bytes; i++)
    buff[i] = 0x00;
  bcm2835_spi_chipSelect(MPU9250_PIN);                      // The default
  bcm2835_spi_transfern(buff,1+Bytes);
  bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);
  memcpy(ReadBuf,buff+1,Bytes);  


  bcm2835_delayMicroseconds(50);

}
Ejemplo n.º 10
0
int main(int argc, char **argv)
{
    // If you call this, it will not actually access the GPIO
    // Use for testing
    //        bcm2835_set_debug(1);

    if (!bcm2835_init())
    {
        return 1;
    }

    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_65536); // The default
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default

    int i;
    for( i = 0; i < 100; i++ )
    {
        // Send a byte to the slave and simultaneously read a byte back from the slave
        // If you tie MISO to MOSI, you should read back what was sent
        uint8_t data = bcm2835_spi_transfer(i);
        printf("Wrote: %02X Read from SPI: %02X\n", i, data);
    }

    bcm2835_spi_end();
    bcm2835_close();
    return 0;
}
Ejemplo n.º 11
0
/**
 * @ingroup SPI-DIO
 *
 * @param device_info
 */
inline static void dio_spi_setup(const device_info_t *device_info) {
#ifdef __AVR_ARCH__
#else
	bcm2835_spi_setClockDivider(1000); // 250kHz
	bcm2835_spi_chipSelect(device_info->chip_select);
#endif
}
Ejemplo n.º 12
0
int main(int argc, char **argv){
	if (!bcm2835_init())
		return 1;

	// SPI INIT
	bcm2835_spi_begin();
	bcm2835_spi_setClockDivider(SPI_CLOCK_DIVIDER_26); 			// 250MHz / 26 = 9.6MHz
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); 				// CPOL = 0, CPHA = 0
	bcm2835_spi_chipSelect(BCM2835_SPI_CS1);					// chip select 1

	HRF_config_FSK();
	HRF_wait_for(ADDR_IRQFLAGS1, MASK_MODEREADY, true);			// wait until ready after mode switching
	HRF_clr_fifo();


	printf("send LEGACY message:\t");
	static bool switchState = false;
	switchState = !switchState;
	bcm2835_gpio_write(LEDR, switchState);

	// THE MAGIC LINE
	relayState = 0;												//0 = s1 on, 1 = s1 off, 2 = s2 on, 3 = s2 off (I think)
	// END MAGIC LINE

	HRF_send_OOK_msg(relayState);

	bcm2835_spi_end();
	return 0;
}
Ejemplo n.º 13
0
/**
 * @ingroup SPI-DO
 *
 * @param device_info
 */
inline void static relay_spi_setup(const device_info_t *device_info) {
#ifdef __AVR_ARCH__
#else
	bcm2835_spi_setClockDivider(2500); // 100kHz
	bcm2835_spi_chipSelect(device_info->chip_select);
#endif
}
Ejemplo n.º 14
0
	void Rfid::init_rfid(void)
	{
		if(geteuid()!=0 || getenv("FAKEROOTKEY"))
		{
			(*_pLinkToConsole)->printOut("You need to be root to properly run this program");
			throw "You need to be root to properly run this program";
		}
		if(!bcm2835_init())
		{
			(*_pLinkToConsole)->printOut("Not able to initialize BCM2835");
			throw "Not able to initialize BCM2835";
		}

		bcm2835_spi_begin();
		bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);	// default
		bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);					// default
		bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32);	// default
		bcm2835_spi_chipSelect(BCM2835_SPI_CS0);					// default
		bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);	// default

		/*
		uid_t uid=500;
		setuid(uid);
		*/

		InitRc522();
	}
Ejemplo n.º 15
0
/**
 *
 * @param dmx_device_info
 */
static void ws2812_zero(dmx_device_info_t *dmx_device_info, const uint8_t *dmx_data) {
	int i,j;

	bcm2835_spi_setClockDivider((uint16_t) ((uint32_t) BCM2835_CORE_CLK_HZ / (uint32_t) 6400000));
	bcm2835_spi_chipSelect(dmx_device_info->device_info.chip_select);					// Just in case we have a multiplexer
	bcm2835_spi_setChipSelectPolarity(dmx_device_info->device_info.chip_select, LOW);	// Just in case we have a multiplexer
	// Clear TX and RX fifos
	BCM2835_PERI_SET_BITS(BCM2835_SPI0->CS, BCM2835_SPI0_CS_CLEAR, BCM2835_SPI0_CS_CLEAR);
	// Set TA = 1
	BCM2835_PERI_SET_BITS(BCM2835_SPI0->CS, BCM2835_SPI0_CS_TA, BCM2835_SPI0_CS_TA);

	for (i = 0; i < ((int) dmx_device_info->pixel_count * (int) WS2812_SLOTS_PER_PIXEL); i++) {
		for (j = 0; j < 8; j++) {
			// Maybe wait for TXD
			while (!(BCM2835_SPI0->CS & BCM2835_SPI0_CS_TXD))
				;

			BCM2835_SPI0->FIFO = (uint32_t) WS2812_LOW_CODE;

			while ((BCM2835_SPI0->CS & BCM2835_SPI0_CS_RXD)) {
				(void) BCM2835_SPI0->FIFO;
			}
		}
	}

	// Wait for DONE to be set
	while (!(BCM2835_SPI0->CS & BCM2835_SPI0_CS_DONE)) {
		while ((BCM2835_SPI0->CS & BCM2835_SPI0_CS_RXD)) {
			(void) BCM2835_SPI0->FIFO;
		}
	}

	// Set TA = 0
	BCM2835_PERI_SET_BITS(BCM2835_SPI0->CS, 0, BCM2835_SPI0_CS_TA);
}
Ejemplo n.º 16
0
Archivo: spi.c Proyecto: sjhx/etrv
int spi_init() {
	int ret = 0;

	mode = 0;
	delay = 0;

#ifdef BCM
	if (!bcm2835_init())
		return 0;
	bcm2835_spi_begin();	
	bcm2835_spi_setClockDivider(SPI_CLOCK_DIVIDER); 			// 250MHz / 26 = 9.6MHz
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); 				// CPOL = 0, CPHA = 0
	bcm2835_spi_chipSelect(BCM2835_SPI_CS1);					// chip select 1
	return 1;
#else
	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("can't open device");

	/*
	 * spi mode
	 */
	ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
	if (ret == -1)
		pabort("can't set spi mode");

	ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
	if (ret == -1)
		pabort("can't get spi mode");

	/*
	 * bits per word
	 */
	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't set bits per word");

	ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't get bits per word");

	/*
	 * max speed hz
	 */
	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't set max speed hz");

	ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't get max speed hz");

	printf("spi mode: %d\n", mode);
	printf("bits per word: %d\n", bits);
	printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

	return 1;
#endif
}
Ejemplo n.º 17
0
/**
 * @ingroup SPI-LCD
 *
 * @param device_info
 */
inline static void lcd_spi_setup(const device_info_t *device_info) {
#ifdef __AVR_ARCH__
#else
	bcm2835_spi_setClockDivider(device_info->internal_clk_div);
	bcm2835_spi_chipSelect(device_info->chip_select);
	bcm2835_spi_setChipSelectPolarity(device_info->chip_select, LOW);
#endif
}
Ejemplo n.º 18
0
uint8_t SPICom::CS1_transfer(uint8_t send_data) {
    if (chipSelect != BCM2835_SPI_CS1) {
        bcm2835_spi_setClockDivider(clockCS1);
        bcm2835_spi_chipSelect(BCM2835_SPI_CS1);
        chipSelect = BCM2835_SPI_CS1;
    }

    return bcm2835_spi_transfer(send_data);
}
Ejemplo n.º 19
0
void SpiPlateformImplementation::setChipSelect( SpiChipSelect cs)
{

#ifdef TARGET_RASPBERRY_PI

    bcm2835_spi_chipSelect( _cs );
    
#endif
}
Ejemplo n.º 20
0
byte SPIClass::transfer(byte _data)
{
  //Set which CS pin to use for next transfers
  bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
  //Transfer 1 byte
  byte data;
  data = bcm2835_spi_transfer((uint8_t)_data);
  return data;
}
Ejemplo n.º 21
0
 //
// Set up a memory regions to access GPIO
//
void setup_io()
{
   /* open /dev/mem */
   if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
      printf("can't open /dev/mem \n");
      exit(-1);
   }
 
   /* mmap GPIO */
   gpio_map = mmap(
      NULL,             //Any adddress in our space will do
      BLOCK_SIZE,       //Map length
      PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
      MAP_SHARED,       //Shared with other processes
      mem_fd,           //File to map
      GPIO_BASE         //Offset to GPIO peripheral
   );
   if (gpio_map == MAP_FAILED) {
      printf("mmap error %d\n", (int)gpio_map);//errno also set!
      exit(-1);
   }
   // Always use volatile pointer!
   gpio = (volatile unsigned *)gpio_map;

#define CLK_LEN   0xA8   
   gpio_map = mmap(
      NULL,             //Any adddress in our space will do
      CLK_LEN,       //Map length
      PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
      MAP_SHARED,       //Shared with other processes
      mem_fd,           //File to map
      CLOCK_BASE         //Offset to GPIO peripheral
   );
    if (gpio_map == MAP_FAILED) {
      printf("mmap error %d\n", (int)gpio_map);//errno also set!
      exit(-1);
   }
   // Always use volatile pointer!
   clkReg = (volatile unsigned *)gpio_map;
   
   close(mem_fd); //No need to keep mem_fd open after mmap

   if (!bcm2835_init())
   {
		printf("bcm2835_init error\n");
		exit(-1);   
   }
#if 0   
    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_4); 
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default   
#endif
} // setup_io
Ejemplo n.º 22
0
int spi_init() {
    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_65536); // The default
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256); // The default
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default

    return 0;
}
Ejemplo n.º 23
0
/**
 *@brief Initializes the SPI peripheral
 *@return none
 */
void SPI_Initialize(void)
{	if (!bcm2835_init())
	{
		printf("BCM libray error.\n");			//Should be run with the sudo cmd
	}
	bcm2835_spi_begin();						//Configure SPI pins
	bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      	//Configure bit order
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);  			//Set clock polarity and phase CPOL=0, CPHA=0
	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_4);	//SPI baud rate at 244 Khz
	bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);			//Control CE0 in software
	printf("SPI initialized...\n");
}
Ejemplo n.º 24
0
// initialization of GPIO and SPI
// ----------------------------------------------------------
void TFT_init_board ( void )
{
	// *************** set the pins to be an output and turn them on
	
	bcm2835_gpio_fsel( OE, BCM2835_GPIO_FSEL_OUTP );
	bcm2835_gpio_write( OE, HIGH );
	
	bcm2835_gpio_fsel( RAIO_RST, BCM2835_GPIO_FSEL_OUTP );
	bcm2835_gpio_write( RAIO_RST, HIGH );

    bcm2835_gpio_fsel( RAIO_CS, BCM2835_GPIO_FSEL_OUTP );
	bcm2835_gpio_write( RAIO_CS, HIGH );
		
	bcm2835_gpio_fsel( RAIO_RS, BCM2835_GPIO_FSEL_OUTP );
	bcm2835_gpio_write( RAIO_RS, HIGH );

    bcm2835_gpio_fsel( RAIO_WR, BCM2835_GPIO_FSEL_OUTP );
    bcm2835_gpio_write( RAIO_WR, HIGH );
	
	bcm2835_gpio_fsel( RAIO_RD, BCM2835_GPIO_FSEL_OUTP );
	bcm2835_gpio_write( RAIO_RD, HIGH );
	
	
	// *************** now the inputs
	
	bcm2835_gpio_fsel( RAIO_WAIT, BCM2835_GPIO_FSEL_INPT );
	bcm2835_gpio_set_pud( RAIO_WAIT, BCM2835_GPIO_PUD_UP);
	
	bcm2835_gpio_fsel( RAIO_INT, BCM2835_GPIO_FSEL_INPT );
	bcm2835_gpio_set_pud( RAIO_INT, BCM2835_GPIO_PUD_UP);
	
		
	// *************** set pins for SPI
	
    bcm2835_gpio_fsel(MISO, BCM2835_GPIO_FSEL_ALT0); 
    bcm2835_gpio_fsel(MOSI, BCM2835_GPIO_FSEL_ALT0); 
    bcm2835_gpio_fsel(SCLK, BCM2835_GPIO_FSEL_ALT0);
    bcm2835_gpio_fsel(SPI_CE1, BCM2835_GPIO_FSEL_ALT0);
        
    // set the SPI CS register to the some sensible defaults
    volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/8;
    bcm2835_peri_write( paddr, 0 ); // All 0s
    
    // clear TX and RX fifos
    bcm2835_peri_write_nb( paddr, BCM2835_SPI0_CS_CLEAR );
    
	bcm2835_spi_setBitOrder( BCM2835_SPI_BIT_ORDER_MSBFIRST );      
    bcm2835_spi_setDataMode( BCM2835_SPI_MODE0 );                 
    bcm2835_spi_setClockDivider( BCM2835_SPI_CLOCK_DIVIDER_2 ); 
    bcm2835_spi_chipSelect( BCM2835_SPI_CS1 );                      
    bcm2835_spi_setChipSelectPolarity( BCM2835_SPI_CS1, LOW );    
}
Ejemplo n.º 25
0
/**
 * @ingroup DEV
 *
 * @param dmx_device_info
 */
static void ws2812(dmx_device_info_t * dmx_device_info, const uint8_t *dmx_data) {
	int i;
	uint8_t mask = 0x80;
	uint16_t dmx_data_index = dmx_device_info->dmx_start_address;

	bcm2835_spi_setClockDivider((uint16_t) ((uint32_t) BCM2835_CORE_CLK_HZ / (uint32_t) 6400000));
	bcm2835_spi_chipSelect(dmx_device_info->device_info.chip_select);					// Just in case we have a multiplexer
	bcm2835_spi_setChipSelectPolarity(dmx_device_info->device_info.chip_select, LOW);	// Just in case we have a multiplexer

	// Clear TX and RX fifos
	BCM2835_PERI_SET_BITS(BCM2835_SPI0->CS, BCM2835_SPI0_CS_CLEAR, BCM2835_SPI0_CS_CLEAR);
	// Set TA = 1
	BCM2835_PERI_SET_BITS(BCM2835_SPI0->CS, BCM2835_SPI0_CS_TA, BCM2835_SPI0_CS_TA);

	for (i = 0; i < ((int)dmx_device_info->pixel_count * (int)WS2812_SLOTS_PER_PIXEL); i++) {
		if (dmx_data_index > DMX_UNIVERSE_SIZE) {
			break;
		}

		mask = 0x80;

		while (mask != 0) {
			// Maybe wait for TXD
			while (!(BCM2835_SPI0->CS & BCM2835_SPI0_CS_TXD))
				;

			if (dmx_data[dmx_data_index] & mask) {
				BCM2835_SPI0->FIFO = (uint32_t) WS2812_HIGH_CODE;
			} else {
				BCM2835_SPI0->FIFO = (uint32_t) WS2812_LOW_CODE;
			}

			while ((BCM2835_SPI0->CS & BCM2835_SPI0_CS_RXD)) {
				(void) BCM2835_SPI0->FIFO;
			}

			mask >>= 1;
		}

		dmx_data_index++;
	}

	// Wait for DONE to be set
	while (!(BCM2835_SPI0->CS & BCM2835_SPI0_CS_DONE)) {
		while ((BCM2835_SPI0->CS & BCM2835_SPI0_CS_RXD)) {
			(void) BCM2835_SPI0->FIFO;
		}
	}

	// Set TA = 0
	BCM2835_PERI_SET_BITS(BCM2835_SPI0->CS, 0, BCM2835_SPI0_CS_TA);
}
Ejemplo n.º 26
0
static PyObject *
PyBCM2835_spi_chipSelect(PyObject *self, PyObject *args)
{
	uint8_t cs;

	if (!PyArg_ParseTuple(args,"i",&cs)) {
		return NULL;
	}

	bcm2835_spi_chipSelect(cs);

	Py_RETURN_NONE;
}
Ejemplo n.º 27
0
void SPI_Init() {
	bcm2835_init();

	bcm2835_spi_begin();

	bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, 0);
	bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, 0);

	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64);

	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
	bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
}
Ejemplo n.º 28
0
static PyObject *
PyBCM2835_spi_setBitOrder(PyObject *self, PyObject *args)
{
	uint8_t order;

	if (!PyArg_ParseTuple(args,"i",&order)) {
		return NULL;
	}

	bcm2835_spi_chipSelect(order);

	Py_RETURN_NONE;
}
/*!
 * Start the SPI communication
 */
void EcgCapture::spiInit()
{
    bcm2835_gpio_fsel(PIN18, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_write(PIN18, LOW);
    delay(100);
    bcm2835_gpio_write(PIN18, HIGH);
    delay(100);
    bcm2835_spi_begin();
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_512);
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);
    bcm2835_gpio_fsel(PIN16, BCM2835_GPIO_FSEL_INPT);
}
Ejemplo n.º 30
0
uint8_t SlushMotor::SPIXfer(uint8_t data) {
	char dataPacket[1];

	dataPacket[0] = (char) data;

	bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);
	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64);
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE3);

	bcm2835_gpio_clr(m_nSpiChipSelect);
	bcm2835_spi_transfern(dataPacket, 1);
	bcm2835_gpio_set(m_nSpiChipSelect);

	return (uint8_t) dataPacket[0];
}