// Read a register from the sensor byte AP_OpticalFlow_ADNS3080_APM2::read_register(byte address) { byte result = 0, junk = 0; backup_spi_settings(); // take the chip select low to select the device digitalWrite(_cs_pin, LOW); // send the device the register you want to read: junk = SPI_transfer(address); // small delay delayMicroseconds(SPI3_DELAY); // send a value of 0 to read the first byte returned: result = SPI_transfer(0x00); // take the chip select high to de-select: digitalWrite(_cs_pin, HIGH); restore_spi_settings(); return result; }
static void SPI_write(int addr, unsigned int c) { SELECT; SPI_transfer(((addr & 0xff00) >> 8) | 0x80); SPI_transfer(addr & 0xff); SPI_transfer(c); DESELECT; }
void MFRC522_Wr( char addr, char value ) { MFRC522_CS = 0; SPI_transfer( ( addr << 1 ) & 0x7E ); SPI_transfer( value ); MFRC522_CS = 1; }
uint8_t send_command(uint8_t cmd, uint32_t argum) { uint8_t error_flag, send_val, return_val, index; if(cmd < 64) { send_val = 0x40 | cmd; error_flag = SPI_transfer(send_val, &return_val); index = 24; while((error_flag == NO_ERRORS)&(index<25)) { send_val = (uint8_t)(argum >> index); error_flag = SPI_transfer(send_val, &return_val); index -= 8; } if(cmd == 0) send_val = 0x95; else if(cmd == 8) send_val = 0x87; else send_val = 0x01; if(error_flag == NO_ERRORS) error_flag = SPI_transfer(send_val, &return_val); if(error_flag != NO_ERRORS) error_flag = SPI_ERROR; }
void FLASH_write_disable(void) { while (FLASH_is_busy()) { } P2OUT &= ~PORT2_FLASH_CS; // CS low SPI_transfer(FLASH_WRDI); P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(FLASH_NOP); }
uint8_t FLASH_busy() { FLASH_SELECT; SPI_transfer(SPIFLASH_STATUSREAD); uint8_t status = SPI_transfer(0); FLASH_UNSELECT; return status & 1; }
bool FLASH_is_busy(void) { P2OUT &= ~PORT2_FLASH_CS; // CS low SPI_transfer(FLASH_RDSR); bool busy = 0 != (FLASH_WIP & SPI_transfer(0xff)); P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(FLASH_NOP); return busy; }
static void SPI_write16(int addr, unsigned int val) { SELECT; SPI_transfer(((addr & 0xff00) >> 8) | 0x80); SPI_transfer(addr & 0xff); SPI_transfer(val & 0xff); SPI_transfer((val >> 8) & 0xff); DESELECT; }
void Write_MFRC522(uchar addr, uchar val) { HW_SPI_SELECT(); SPI_transfer(FileDescriptor,(addr<<1)&0x7E); SPI_transfer(FileDescriptor,val); HW_SPI_UNSELECT(); }
void Write_MFRC522(uchar addr, uchar val) { HW_SPI_SELECT(); SPI_transfer((addr<<1)&0x7E); SPI_transfer(val); HW_SPI_UNSELECT(); }
static void SPI_fill(int addr, unsigned short value, size_t count) { SELECT; SPI_transfer(((addr & 0xff00) >> 8) | 0x80); SPI_transfer(addr & 0xff); while (count-- > 0) { SPI_transfer(value); } DESELECT; }
/** * This method fills the gameduinos memory with data from the byte array * \param addr The address to write to * \param bytes The char array to read from * \param length The number of bytes to write */ static void SPI_write_bytes(int addr, char* bytes, size_t length) { SELECT; SPI_transfer(((addr & 0xff00) >> 8) | 0x80); SPI_transfer(addr & 0xff); while (length-- > 0) { SPI_transfer(*bytes++); } DESELECT; }
/** * This method fills a char array with data from the gameduinos memory * \param addr The address to read from * \param bytes The char array to write in * \param length The number of bytes to read */ static void SPI_read_bytes(int addr, char* bytes, size_t length) { SELECT; SPI_transfer((addr & 0xff00) >> 8); SPI_transfer(addr & 0xff); while (length-- > 0) { *bytes++ = SPI_transfer(0); } DESELECT; }
uint8_t Read_MFRC522(uchar addr) { uchar val; HW_SPI_SELECT(); SPI_transfer(FileDescriptor,((addr<<1)&0x7E) | 0x80); val =SPI_transfer(FileDescriptor,0x00); HW_SPI_UNSELECT(); return val; }
// Read the status register byte DataFlash_APM2::ReadStatusReg() { CS_inactive(); // Reset dataflash command decoder CS_active(); // Read status command SPI_transfer(DF_STATUS_REGISTER_READ); return SPI_transfer(0x00); // We only want to extract the READY/BUSY bit }
char MFRC522_Rd( char addr ) { char value; MFRC522_CS = 0; SPI_transfer( (( addr << 1 ) & 0x7E) | 0x80 ); value = SPI_transfer( 0x00 ); MFRC522_CS = 1; return value; }
uint8_t FLASH_readByte(uint32_t addr) { FLASH_command(SPIFLASH_ARRAYREADLOWFREQ, 0); SPI_transfer(addr >> 16); SPI_transfer(addr >> 8); SPI_transfer(addr); //SPI.transfer(0); //"dont care", needed with SPIFLASH_ARRAYREAD command only uint8_t result = SPI_transfer(0); FLASH_UNSELECT; return result; }
void WriteToCC1020Register(unsigned char addr, unsigned char data) { cbi(PORTB, SS); addr = (addr << 1) | 0x01; SPI_transfer(addr); SPI_transfer(data); sbi(PORTB, SS); }
static unsigned short SPI_read(int addr) { unsigned short byteRead; SELECT; SPI_transfer((addr & 0xff00) >> 8); SPI_transfer(addr & 0xff); byteRead = SPI_transfer(0); DESELECT; return byteRead; }
void FLASH_info(uint8_t *maufacturer, uint16_t *device) { P2OUT &= ~PORT2_FLASH_CS; // CS low SPI_transfer(FLASH_RDID); *maufacturer = SPI_transfer(FLASH_NOP); uint8_t id_high = SPI_transfer(FLASH_NOP); uint8_t id_low = SPI_transfer(FLASH_NOP); *device = (id_high << 8) | id_low; P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(FLASH_NOP); }
void FLASH_sector_erase(uint32_t address) { while (FLASH_is_busy()) { } P2OUT &= ~PORT2_FLASH_CS; // CS low SPI_transfer(FLASH_SE); SPI_transfer(address >> 16); SPI_transfer(address >> 8); SPI_transfer(address); P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(FLASH_NOP); }
// This function is mainly to test the device void DataFlash_APM2::ReadManufacturerID() { CS_inactive(); // Reset dataflash command decoder CS_active(); // Read manufacturer and ID command... SPI_transfer(DF_READ_MANUFACTURER_AND_DEVICE_ID); df_manufacturer = SPI_transfer(0xff); df_device = SPI_transfer(0xff); df_device = (df_device<<8) | SPI_transfer(0xff); SPI_transfer(0xff); }
unsigned char ReadFromCC1020Register(unsigned char addr) { cbi(PORTB, SS); char Value; addr = (addr << 1) & 0xFE; SPI_transfer(addr); Value = SPI_transfer(0xFF); sbi(PORTB, SS); return Value; }
// return true if the chip is supported bool FLASH_initialise(void) { P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(0xff); // flush the SPI buffers SPI_transfer(0xff); // .. SPI_transfer(0xff); // .. uint8_t maufacturer; uint16_t device; FLASH_info(&maufacturer, &device); return (FLASH_MFG == maufacturer) && (FLASH_ID == device); }
void DataFlash_APM2::PageToBuffer(unsigned char BufferNum, uint16_t PageAdr) { CS_inactive(); CS_active(); if (BufferNum==1) SPI_transfer(DF_TRANSFER_PAGE_TO_BUFFER_1); else SPI_transfer(DF_TRANSFER_PAGE_TO_BUFFER_2); if(df_PageSize==512){ SPI_transfer((unsigned char)(PageAdr >> 7)); SPI_transfer((unsigned char)(PageAdr << 1)); }else{
char SD_init() { char i; CS_DISABLE(); for (i = 0; i < 10; i++) SPI_transfer(0xFF); #ifdef DEBUG USART_printstr("\r\n"); #endif for (i = 0; i < 10 && SD_command(0x40, 0x00000000, 0x95, 8) != 1; i++) { _delay_ms(100); #ifndef DEBUG USART_printch('.'); #endif } if (i == 10) return -1; for (i = 0; i < 10 && SD_command(0x41, 0x00000000, 0xFF, 8) != 0; i++) { _delay_ms(100); #ifndef DEBUG USART_printch('.'); #endif } if (i == 10) return -2; SD_command(0x50, 0x00000200, 0xFF, 8); return 0; }
void FLASH_read(void *buffer, uint32_t address, uint16_t length) { P2OUT &= ~PORT2_FLASH_CS; // CS low SPI_transfer(FLASH_FAST_READ); SPI_transfer(address >> 16); SPI_transfer(address >> 8); SPI_transfer(address); SPI_transfer(FLASH_NOP); // read dummy byte for (uint8_t *p = (uint8_t *)buffer; length != 0; --length) { *p++ = SPI_transfer(FLASH_NOP); } P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(FLASH_NOP); }
void spiLcd_Init() { SPI_Handle handle; SPI_Params params; SPI_Transaction transaction; //PIN_Id csnPin1 = PIN_ID(Board_CSN_1); uint8_t txBuf[] = "Hello World"; // Transmit buffer // Init SPI and specify non-default parameters SPI_Params_init(¶ms); params.bitRate = 1000000; params.frameFormat = SPI_POL1_PHA1; params.mode = SPI_MASTER; // Configure the transaction transaction.count = sizeof(txBuf); transaction.txBuf = txBuf; transaction.rxBuf = NULL; // Open the SPI and perform transfer to the first slave handle = SPI_open(Board_SPI0, ¶ms); SPI_transfer(handle, &transaction); // Then switch chip select pin and perform transfer to the second slave //SPI_control(handle, SPICC26XXDMA_SET_CSN_PIN, &csnPin1); //SPI_transfer(handle, &transaction); }
/************************************************** * Function name : * Created by : * Date created : * Description : * Notes : ***************************************************/ void read_callback(U8 *Rx_buffer, U8 length) { ss_high(); __delay_cycles(1000); ss_low(); SPI_transfer (0, read_packet.read_frame, 7, control_callback); }
void FLASH_write(uint32_t address, void *buffer, uint16_t length) { while (FLASH_is_busy()) { } P2OUT &= ~PORT2_FLASH_CS; // CS low SPI_transfer(FLASH_PP); SPI_transfer(address >> 16); SPI_transfer(address >> 8); SPI_transfer(address); for (uint8_t *p = (uint8_t *)buffer; length != 0; --length) { SPI_transfer(*p++); } P2OUT |= PORT2_FLASH_CS; // CS high SPI_transfer(FLASH_NOP); }