Exemple #1
0
void SPI::beginTransaction(SPISettings settings) {

    pthread_mutex_lock (&spiMutex);
    setBitOrder(settings.border);
    setDataMode(settings.dmode);
    setClockDivider(settings.clck);
}
Exemple #2
0
void _CoreSPI::begin() {
    // Set the SPI0 pins to the Alt 0 function to enable SPI0 access on them
//    GPIO.selectFunction(CS0, FSEL_ALT0);
//    GPIO.selectFunction(CS1, FSEL_ALT0);
    GPIO.selectFunction(MISO, FSEL_ALT0);
    GPIO.selectFunction(MOSI, FSEL_ALT0);
    GPIO.selectFunction(SCK, FSEL_ALT0);

    map_peripheral(&spi);
    reg = (bcm2835_spi_registers *)spi.map;
    reg->cs_val = 0;
    sync_peripheral(&spi);
    reg->cs.clear = 0b11;
    reg->cs.cs = 0b11;

    sync_peripheral(&spi);

    setClockDivider(SPI_CLOCK_DIV256);
//    setChipSelectPolarity(SPI_CS0, LOW);
//    setChipSelectPolarity(SPI_CS1, LOW);
//    setChipSelectPolarity(SPI_CS2, LOW);
//    chipSelect(SPI_CS0);
    started = true;

}
Exemple #3
0
BroadcomI2C::Result BroadcomI2C::initialize()
{
    // Map I2C registers
    if (m_io.map(IO_BASE + BSC1, PAGESIZE,
                 Memory::User|Memory::Readable|Memory::Writable|Memory::Device) != IO::Success)
        return IOError;

    // Initialize GPIO controller
    if (m_gpio.initialize() != BroadcomGPIO::Success)
        return IOError;

    // Set GPIO pins to ALT0 function for SDA, SCL pins
    m_gpio.setAltFunction(2, BroadcomGPIO::Function0);
    m_gpio.setAltFunction(3, BroadcomGPIO::Function0);

    // Detect I2C controller. In Qemu, the ClockDivider is always zero.
    if (m_io.read(ClockDivider) == 0)
    {        
        return NotFound;
    }

    // Set a slow clock to attempt workaround the I2C bug in Broadcom 2835
    setClockDivider(0x5dc * 3);
    DEBUG("I2C GPIO pins set");
    DEBUG("ClockDivider is " << m_io.read(ClockDivider));
    DEBUG("Status is " << m_io.read(Status));

    // Done
    return Success;
}
Exemple #4
0
void SPIClass::begin()
{
  if (!initialized) {
    void *pciDev = NULL;

	// Get SPI device base address
	pciDev = pci_Alloc(0x00, 0x10, 0x01); // PCI SPI configuration space
	if(pciDev == NULL) {printf("SPI device don't exist\n"); return;}
	SPI_IOaddr = (unsigned)(pci_In16(pciDev, 0x10) & 0xFFFFFFF0L); // get SPI base address
	#if defined DEBUG_MODE
	printf("SPI base address = %04X\n", SPI_IOaddr);
	#endif
	pci_Free(pciDev);

    WriteCTRR(FULLDUPEX + SPI_MODE0 + RESET);

	io_outpb(SPI_IOaddr + 7, FULLDUPEX); // full-dupex
	io_outpb(SPI_IOaddr + 7, io_inpb(SPI_IOaddr + 7) & 0xF1 | SPI_MODE0); // set mode
	io_outpb(SPI_IOaddr + 0x0b, 0x08); // delay clk between two transfers
    //SOURCE clock/(2 * SPI_CLOCK_DIV)
	setClockDivider(13); // 100/(2*13) ~= 4MHz
	useFIFO();
	detachInterrupt();

	io_outpb(SPI_IOaddr + 4, 0x01); // set CS = high

	// Set SS to high so a connected chip will be "deselected" by default
	pinMode(SS, OUTPUT);
	digitalWrite(SS, HIGH);
  }
  initialized++; // reference count
}
void SPIClass::begin()
{
    init();
    // NPCS control is left to the user
    // Default speed set to 4Mhz
    setClockDivider(BOARD_SPI_DEFAULT_SS, 21);
    setDataMode(BOARD_SPI_DEFAULT_SS, SPI_MODE0);
    setBitOrder(BOARD_SPI_DEFAULT_SS, MSBFIRST);
}
Exemple #6
0
void SPIClass::begin() {
	initCb();
	SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
	SPI_Enable(spi);

	// NPCS control is left to the user

	// Default speed set to 4Mhz
	setClockDivider(BOARD_SPI_DEFAULT_SS, 21);
	setDataMode(BOARD_SPI_DEFAULT_SS, SPI_MODE0);
	setBitOrder(BOARD_SPI_DEFAULT_SS, MSBFIRST);
}
Exemple #7
0
SSP1::SSP1()			//define constructor
{
	this->port = LPCXSSP1;
	bitOrder = LSBFIRST;
	divider = SPI_CLOCK_DIV4;	//Arduino's default
	dataMode = SPI_MODE0;
	bitlength = 8;
	setClockDivider(divider);
	setBitLength(bitlength);
	setBitOrder(LSBFIRST);
	begin();
}
Exemple #8
0
void WIFI_SPIClass::begin() {
	void *pciDev = NULL;
	
	if(io_Init() == false)
		return;
	
	// Get SPI device base address	
	pciDev = pci_Alloc(0x00, 0x10, 0x01); // PCI SPI configuration space
	if(pciDev == NULL) {printf("WiFi-SPI device don't exist\n"); return;}
	WIFI_SPI_IOaddr = (unsigned)(pci_In16(pciDev, 0x10) & 0xFFFFFFF0L); // get SPI base address
	#if defined WIFI_DEBUG_MODE
	printf("WiFi-SPI base address = %04X\n", WIFI_SPI_IOaddr);
	#endif
	pci_Free(pciDev);
  
    WIFI_WriteCTRR(WIFI_FULLDUPEX + WIFI_SPI_MODE0 + WIFI_RESET);
    
	io_outpb(WIFI_SPI_IOaddr + 7, WIFI_FULLDUPEX); // full-dupex
	io_outpb(WIFI_SPI_IOaddr + 7, io_inpb(WIFI_SPI_IOaddr + 7) & 0xF1 | WIFI_SPI_MODE0); // set mode
	io_outpb(WIFI_SPI_IOaddr + 0x0b, 0x08); // delay clk between two transfers
    //SOURCE clock/(2 * SPI_CLOCK_DIV)
	setClockDivider(WIFI_SPI_CLOCK_DIV800); // 125k Hz
	WIFI_useFIFO();
	detachInterrupt();
    
	io_outpb(WIFI_SPI_IOaddr + 4, 0x01); // set CS = high
  
	// Set SS to high so a connected chip will be "deselected" by default
	digitalWrite(SS, HIGH);
	
	// When the SS pin is set as OUTPUT, it can be used as
	// a general purpose output port (it doesn't influence
	// SPI operations).
	//pinMode(SS, OUTPUT);
	
	// Warning: if the SS pin ever becomes a LOW INPUT then SPI
	// automatically switches to Slave, so the data direction of
	// the SS pin MUST be kept as OUTPUT.
	//SPCR |= _BV(MSTR);
	//SPCR |= _BV(SPE);
	
	// Set direction register for SCK and MOSI pin.
	// MISO pin automatically overrides to INPUT.
	// By doing this AFTER enabling SPI, we avoid accidentally
	// clocking in a single bit since the lines go directly
	// from "input" to SPI control.  
	// http://code.google.com/p/arduino/issues/detail?id=888
	//pinMode(SCK, OUTPUT);
	//pinMode(MOSI, OUTPUT);
}
void SPIClass::begin(uint8_t _pin)
{
    init();
    uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin);
    PIO_Configure(
        g_APinDescription[spiPin].pPort,
        g_APinDescription[spiPin].ulPinType,
        g_APinDescription[spiPin].ulPin,
        g_APinDescription[spiPin].ulPinConfiguration);
    // Default speed set to 4Mhz
    setClockDivider(_pin, 21);
    setDataMode(_pin, SPI_MODE0);
    setBitOrder(_pin, MSBFIRST);
}
Exemple #10
0
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);
}
Exemple #11
0
void SPIClass::setClock(uint32_t rate){
  setClockDivider(SPI0F2DIV(rate));
}