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 ); */ } }
// 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 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(); }
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); }
bool bw_spi_dimmer_start(device_info_t *device_info) { if (device_info->slave_address == (uint8_t) 0) { device_info->slave_address = BW_DIMMER_DEFAULT_SLAVE_ADDRESS; } if (device_info->speed_hz == (uint32_t) 0) { device_info->speed_hz = (uint32_t) BW_DIMMER_SPI_SPEED_DEFAULT_HZ; } else if (device_info->speed_hz > (uint32_t) BW_DIMMER_SPI_SPEED_MAX_HZ) { device_info->speed_hz = (uint32_t) BW_DIMMER_SPI_SPEED_MAX_HZ; } if (device_info->chip_select >= SPI_CS2) { device_info->chip_select = SPI_CS2; bcm2835_aux_spi_begin(); device_info->internal.clk_div = bcm2835_aux_spi_CalcClockDivider(device_info->speed_hz); } else { bcm2835_spi_begin(); device_info->internal.clk_div = (uint16_t)((uint32_t) BCM2835_CORE_CLK_HZ / device_info->speed_hz); } char id[BW_ID_STRING_LENGTH+1]; bw_spi_read_id(device_info, id); if (memcmp(id, "spi_dimmer", 10) == 0) { return true; } return false; }
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; }
void SPI::begin( int busNo ) { if (!bcm2835_init()) { return; } bcm2835_spi_begin(); }
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; }
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); }
static PyObject * PyBCM2835_spi_begin(PyObject *self, PyObject *args) { bcm2835_spi_begin(); Py_RETURN_NONE; }
/* * 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(); }
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 }
// // 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 SPIClass::begin() { if (!initialized) { if (!bcm2835_spi_begin()) { mys_log(LOG_ERR, "You need to be root to use SPI.\n"); exit(1); } } initialized++; // reference count }
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"); }
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); }
void SPIClass::begin(uint16_t divider, uint8_t bitOrder, uint8_t dataMode) { setClockDivider(divider); setBitOrder(bitOrder); setDataMode(dataMode); //Set CS pins polarity to low bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, 0); bcm2835_spi_begin(); //Initialize a timestamp for millis calculation gettimeofday(&RHStartTime, NULL); }
int bw_spi_dio_start(device_info_t *device_info) { if (bcm2835_init() != 1) return 1; bcm2835_spi_begin(); // Just once. Assuming all devices do have the same bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); if (device_info->slave_address <= 0) device_info->slave_address = BW_DIO_DEFAULT_SLAVE_ADDRESS; return 0; }
/************************************************************************** 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); }
MPU9250::MPU9250() { if (!bcm2835_init()) { printf("bcm2835_init failed. Are you running as root??\n"); } if (!bcm2835_spi_begin()) { printf("bcm2835_spi_begin failedg. Are you running as root??\n"); } 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_16); // The default bcm2835_spi_setChipSelectPolarity(MPU9250_PIN, LOW); // the default bcm2835_spi_chipSelect(MPU9250_PIN); // The default }
void main(int argc, char* argv) { /* Pour le debugging 1 == Print sur la console les operations des fonctions 0 == Comportement normal du programme */ bcm2835_set_debug(0); /* Initialisation de la librairie */ if(bcm2835_close()) { /* code d'initialisation bcm */ printf("Version de la librairie : %d", bcm2835_version()); if(bcm2835_spi_begin()) { /* Initialisation de la SPI Voir header pour valeurs */ bcm2835_spi_setClockDivider(CLK_SPEED); bcm2835_spi_setDataMode(PI_MODE); bcm2835_spi_setBitOrder(BIT_ORDER); /* Selecte un CS pour le transfert de donnees */ bcm2835_spi_chipSelect(CS_SLAVE); /* Test de transfert avec retour */ uint8_t ret; ret = bcm2835_spi_transfer(5); printf("Retour de l'Arduino : %d", ret); /* Test de transfert sans retour */ bcm2835_spi_transfern("A", 1); bcm2835_spi_end(); } else { printf("Erreur de l'init de SPI\n"); } bcm2835_close(void); /* Libere la memoire et ferme la librairie */ } else { printf("Echec de l'ouverture de la librairie\n"); } }
int DIS_init() { if (!bcm2835_init()) return 1; bcm2835_gpio_fsel(DIS_CS1, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(DIS_CS2, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(DIS_CS3, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(DIS_CS4, BCM2835_GPIO_FSEL_OUTP); chipSelect(DIS_NONE); bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); bcm2835_spi_setClockDivider(DIS_CLOCK_DIVIDER); bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); return 0; }
/** * @ingroup DEV * * @param dmx_device_info */ static void ws2812_init(dmx_device_info_t * dmx_device_info, const uint8_t *dmx_data) { struct _rdm_sub_devices_info *rdm_sub_devices_info = &(dmx_device_info)->rdm_sub_devices_info; bcm2835_spi_begin(); (void *)_memcpy(rdm_sub_devices_info, &sub_device_info, sizeof(struct _rdm_sub_devices_info)); dmx_device_info->rdm_sub_devices_info.dmx_start_address = dmx_device_info->dmx_start_address; (void *)_memcpy(dmx_device_info->rdm_sub_devices_info.device_label, device_label, device_label_len); dmx_device_info->rdm_sub_devices_info.device_label_length = device_label_len; // WS2812 specific if ((dmx_device_info->pixel_count == (uint8_t)0) || ((uint16_t) dmx_device_info->pixel_count * (uint16_t) WS2812_SLOTS_PER_PIXEL > (uint16_t) DMX_UNIVERSE_SIZE)) { dmx_device_info->pixel_count = (uint8_t) ((uint16_t) DMX_UNIVERSE_SIZE / (uint16_t) WS2812_SLOTS_PER_PIXEL); } dmx_device_info->rdm_sub_devices_info.dmx_footprint = dmx_device_info->pixel_count * (uint16_t) WS2812_SLOTS_PER_PIXEL; dmx_device_info->rdm_sub_devices_info.rdm_personalities->slots = dmx_device_info->pixel_count * (uint16_t) WS2812_SLOTS_PER_PIXEL; }
int main(int argc, char **argv) { if (!bcm2835_init()) return 1; char buffer[4]; buffer[0] = 50; int i,temp; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); //SCLK rising edge - clock idle state 1 bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); //set clock frequency bcm2835_spi_chipSelect(BCM2835_SPI_CS1); //use chip select 1 bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, LOW); //chip select 0 to activate buffer[0]=buffer[1]=buffer[2]=buffer[3]=0; //bcm2835_spi_transfern(buffer,4); buffer[0] = 0x58; //read the id bcm2835_spi_transfern(buffer,2); printf("id:%02X\n",buffer[1]); while(1) { buffer[0] = 0x50; //read the temp bcm2835_spi_transfern(buffer,3); printf("status %02X %02X\n",buffer[1],buffer[2]); temp = buffer[1]; temp = temp<<8; temp = temp + ( buffer[2] & 0xF8); printf("status %08x\n",temp); temp = temp>>3; temp = temp/16; printf("temp:%d\n",temp); sleep(1); } bcm2835_spi_end(); bcm2835_close(); return 0; }
void init_lcd_spi(void) { bcm2835_init(); 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 bcm2835_gpio_fsel(RPI_GPIO_P1_16, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(RPI_GPIO_P1_22, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(RPI_GPIO_P1_24, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(RPI_GPIO_P1_26, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(PENIRQ, BCM2835_GPIO_FSEL_INPT); bcm2835_gpio_set_pud(PENIRQ, BCM2835_GPIO_PUD_UP);/////////////////////// printf("\n spi-lcd22 test :\n Start .......\n "); }