示例#1
0
bool at45dbx_read_byte_open(uint32_t ad)
{
	uint32_t addr;
	
	if (at45dbx_check_address(ad) == false) {
		return false;
	}

	// Set the global memory pointer to a byte address.
	at45dbx_gl_ptr_mem = ad;

	// If the DF memory is busy, wait until it's ready.
	if (at45dbx_busy) at45dbx_wait_ready();
	at45dbx_busy = false;

	// Select the DF memory at45dbx_gl_ptr_mem points to.
	at45dbx_chipselect_df(at45dbx_gl_ptr_mem >> AT45DBX_MEM_SIZE, true);

	// Initiate a page read at a given sector.

	// Send the Main Memory Page Read command.
	at45dbx_spi_write_byte(AT45DBX_CMDA_RD_PAGE);

	// Send the three address bytes, which comprise:
	//  - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
	//  - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
	//  - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
	// NOTE: The bits of at45dbx_gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
	// DF addressing. They are used for DF discrimination when there are several DFs.
	addr = (Rd_bitfield(at45dbx_gl_ptr_mem, (uint32_t)AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
		Rd_bitfield(at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);

	at45dbx_spi_write_byte(LSB2W(addr));
	at45dbx_spi_write_byte(LSB1W(addr));
	at45dbx_spi_write_byte(LSB0W(addr));

	// Send 32 don't care clock cycles to initialize the read operation.
	at45dbx_spi_write_byte(0x55);
	at45dbx_spi_write_byte(0x55);
	at45dbx_spi_write_byte(0x55);
	at45dbx_spi_write_byte(0x55);
	return true;
}
示例#2
0
文件: at45dbx.c 项目: 00alis/Arduino
Bool at45dbx_read_open(U32 sector)
{
  U32 addr;

  // Set the global memory pointer to a byte address.
  gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.

  // If the DF memory is busy, wait until it's ready.
  if (at45dbx_busy) at45dbx_wait_ready();
  at45dbx_busy = FALSE;

  // Select the DF memory gl_ptr_mem points to.
  at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);

  // Initiate a page read at a given sector.

  // Send the Main Memory Page Read command.
  spi_write(AT45DBX_SPI, AT45DBX_CMDA_RD_PAGE);

  // Send the three address bytes, which comprise:
  //  - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
  //  - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
  //  - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
  // NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
  // DF addressing. They are used for DF discrimination when there are several DFs.
  addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
         Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
  spi_write(AT45DBX_SPI, LSB2W(addr));
  spi_write(AT45DBX_SPI, LSB1W(addr));
  spi_write(AT45DBX_SPI, LSB0W(addr));

  // Send 32 don't care clock cycles to initialize the read operation.
  spi_write_dummy();
  spi_write_dummy();
  spi_write_dummy();
  spi_write_dummy();

  return OK;
}