- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a Max10 Board, first I set it up as a Master (i2c core) and an Arduino Board as a slave, I successfully send and received data.
But when I wanted to add a RAM memory connected to a i2c slave to Avalon MM master bridge it does not work.
When I am trying to transmit the data I keep getting the error [-7], busy.
Here is my code, if someone can help me out:
int main(){
printf("Hello from Nios II!\n");
ALT_AVALON_I2C_DEV_t *i2c_dev; //pointer to instance structure
ALT_AVALON_I2C_MASTER_CONFIG_t cfg;
alt_u8 retry = 0;
alt_u32 *chip_id = 0;
int i;
alt_u8 *ocram[2]; //create slave RAM
ocram[0] = (alt_u8*)(I2C_MEM_0_BASE | 0x80000000);
ocram[1] = (alt_u8*)(I2C_MEM_1_BASE | 0x80000000);
// fill block of memory
for(i=0;i<2;i++){
memset((void*)ocram[i],i, I2C_MEM_0_SIZE_VALUE); // i2c slave memory clear, 256 bytes
}
// Get a pointer to the Avalon i2c block instance
// NOTE: Must match the name on Platform Designer
i2c_dev = alt_avalon_i2c_open("/dev/i2c");
if(NULL==i2c_dev){
printf("Error: Cannot find /dev/i2c\n");
return FALSE;
}
usleep(100);
// Speed settings
alt_avalon_i2c_master_config_speed_set(i2c_dev,&cfg,100000);
alt_avalon_i2c_master_config_set(i2c_dev,&cfg);
//set the address of the device using (32 bits address)
alt_avalon_i2c_master_target_set(i2c_dev,0x50);
// Function: Get i2c Slave ID
while((retry++ < 2)){
alt_avalon_i2c_master_target_get(i2c_dev, chip_id);
printf("Read chip ID: ");
printf("0x%04x\n" , chip_id[0]);
usleep(100);
}
for(i=0;i<2;i++){
i2c_write(i2c_dev,DEV_ADR+i);
}
for(i=0;i<2;i++){
printf("\nI2CSLAVE%d:\n",i);
dump(ocram[i],256);
}
return 0;
}
int i2c_write(ALT_AVALON_I2C_DEV_t *i2c_dev, unsigned char adr){
int i;
alt_u8 txbuffer[MEM_SIZE+BYTE_MODE];
ALT_AVALON_I2C_STATUS_CODE status;
printf("\nADR=%x\n", adr);
usleep(1000000);
//start address of register
txbuffer[0] = WRITE_ADR;
//set value in send buffer
for(i = 0;i<MEM_SIZE;i++){
txbuffer[i+BYTE_MODE] = i|0x80; // some data
}
alt_avalon_i2c_disable(i2c_dev);
dump(txbuffer,MEM_SIZE+BYTE_MODE);
status=alt_avalon_i2c_enable(i2c_dev);
printf("Status[%d]\n",(int)status);
status = alt_avalon_i2c_master_tx(i2c_dev,txbuffer,MEM_SIZE+1, ALT_AVALON_I2C_NO_INTERRUPTS);
if(status !=ALT_AVALON_I2C_SUCCESS){
printf("Error:Tx Fail[%d]\n",(int)status);
return FALSE;
}
printf("data send");
return TRUE;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Daysi
Can you forward to me your Platform Designer connection diagram ?
There will be a synchronizer automatically added where there is a cross clock.
Thanks.
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Daysi
You may refer to page 190 - 199 of below.
https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/ug/ug_embedded_ip.pdf
There are 3 bits of stealing address which you can enable or disable in the control byte.
Please follow the read and write protocol of the IP. And you will need to modify the interface of the I2C of the IP to off chip.
Thanks.
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Daysi
Can we close the case if you have no question ?
Thanks.
Eric

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page