- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm having some trouble reading from my IO expander with the SPI core from Altera :confused: Can anybody provide me with an example on how to issue a correct read to the spi interface with the 'alt_avalon_spi_command' ?? Thanks :) -mitchLink Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use something like that
IOWR(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_TXDATA_REG, tosend);
while (!(IORD(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_STATUS_REG) & 0x0020));
return IORD(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_RXDATA_REG);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
could you show me the your complete code for your spi interface?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I send 16bits. 1 read/write bit, 7 address bits and 8 datas bits.
void WriteReg(alt_u8 adress, alt_u8 m_data)
{
alt_u16 tosend;
tosend = 0x8000 | ((adress << 8) & 0x7F00) | (m_data & 0x00FF);
IOWR(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_TXDATA_REG, tosend);
while (!(IORD(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_STATUS_REG) & 0x0020));
}
alt_u8 ReadReg(alt_u8 adress)
{
alt_u16 tosend;
tosend = (adress << 8) & 0x7F00;
IOWR(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_TXDATA_REG, tosend);
while (!(IORD(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_STATUS_REG) & 0x0020));
return IORD(SPI_CYCLONE3_BASE, ALTERA_AVALON_SPI_RXDATA_REG);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I have the similar problem-i can write to the register, but when i try to read from register, i dont became anything, all signals-CS, CLK, MISO are 0... alt_spi_command run also, but only when i write to register... can anybody help me, any suggestion?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I ended up using the standard NIOS spi command like this:
Write :
wdata = 0x40; // Write command of the chip
wdata = 0x09; // register adr
wdata = 0x2; // value
alt_avalon_spi_command(SPI0_BASE, 0,
3,
wdata,
0,
rdata,
0);
Read :
wdata = 0x41; // read command
wdata = 0x12; // register adr
ID = 0;
alt_avalon_spi_command(SPI0_BASE, 0,
2,
wdata,
2, // reading 2 bytes
rdata, // store bytes here
0);
Hope this helps :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
and how would that work without the standard command?
I'm an altera newbee and have the same problem. i need to send 7 bit reg-addr.+1bit r/w and 16 bit data I'm trying with
#include
<altera_avalon_spi_regs.h>
#include <altera_avalon_spi.h>
main{
int test;
while (!(IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE) & ALTERA_AVALON_SPI_STATUS_TRDY_MSK));
IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_BASE, 0xFFFF);
while (!(IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE) & ALTERA_AVALON_SPI_STATUS_TRDY_MSK));
test=IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE);
}
but the thinks i write dont match with the read data... :( Any help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what pins did you assign your MISO,MOSI,SS,SCK ??
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page