/* * 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(); }
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); } } }
// initializer for SPI - we indicate the pins used and OLED type // boolean ArduiPi_OLED::init(int8_t DC, int8_t RST, int8_t CS, uint8_t OLED_TYPE) { rst = RST==OLED_PIN_DEFAULT ? DEF_SPI_RESET : RST; // Reset Pin dc = DC ==OLED_PIN_DEFAULT ? DEF_SPI_DC : DC; // Data / command Pin cs = CS ==OLED_PIN_DEFAULT ? DEF_SPI_CS : ( CS ==OLED_CS_ALTERNATE ? ALT_SPI_CS : CS); // Raspberry SPI chip Enable (may be CE0 or CE1) // Select OLED parameters if (!select_oled(OLED_TYPE)) return false; // Init & Configure Raspberry PI SPI bcm2835_spi_begin(cs); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // 16 MHz SPI bus, but Worked at 62 MHz also bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16); // Set the pin that will control DC as output bcm2835_gpio_fsel(dc, BCM2835_GPIO_FSEL_OUTP); // Setup reset pin direction as output if (rst >= 0) bcm2835_gpio_fsel(rst, BCM2835_GPIO_FSEL_OUTP); return ( true); }
void setupSPI() { /* //Use bcm2835_gpio_fsel(uint8_t pin, uint8_t mode) to set pin modes //Modes are BCM2835_GPIO_FSEL_INPT for input //Modes are BCM2835_GPIO_FSEL_OUTP for output bcm2835_gpio_fsel(SCLK, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(MOSI, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(MISO, BCM2835_GPIO_FSEL_INPT); //Clear the two output pins bcm2835_gpio_clr(SCLK); bcm2835_gpio_clr(MOSI); bcm2835_gpio_set_pud(SCLK, BCM2835_GPIO_PUD_DOWN); bcm2835_gpio_set_pud(MOSI, BCM2835_GPIO_PUD_DOWN); bcm2835_gpio_set_pud(MISO, BCM2835_GPIO_PUD_UP); */ bcm2835_spi_begin(); //About 1MHz //bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256); //About 244KHz //bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_1024); //bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_2048); //About 30.5kHz //bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_8192); //16KHz bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16384); bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); }
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 ); */ } }
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); }
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; }
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; }
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; }
/** * @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 }
/** * @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 }
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); }
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(); }
/** * * @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); }
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 }
void init_touch_spi(void) { bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256); // The default }
/** * @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 }
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); }
// // 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
void SpiPlateformImplementation::setClockDivider ( SpiClockDivider divider) { // if( divider != s_divider ) { s_divider = divider; #ifdef TARGET_RASPBERRY_PI bcm2835_spi_setClockDivider( s_divider ); #endif } }
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; }
/** *@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"); }
// 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 ); }
/** * @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); }
static PyObject * PyBCM2835_spi_setClockDivider(PyObject *self, PyObject *args) { uint16_t divider; if (!PyArg_ParseTuple(args,"i",÷r)) { return NULL; } bcm2835_spi_setClockDivider(divider); Py_RETURN_NONE; }
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); }
/************************************************************************** Function: spi_lcd_init Purpose: Initialize SPI device Returns: Note: Sets defaults *************************************************************************/ int spi_lcd_init(struct spi_lcd_dev *dev) { // wait for 100ms for power up delay - could probably skip this. bcm2835_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_65536); bcm2835_spi_chipSeclect(BCM2835_SPI_CS0); bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0,LOW); return 0; }
LEDMatrix::LEDMatrix(int width, int height) { this->width = width; this->height = height; //Initialize the color array for(int i = 0; i < (width*height); i++) { colors.push_back(Color()); } //Initialize the BCM2835 library bcm2835_init(); bcm2835_spi_begin(); bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128); }
/*! * 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); }
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]; }