Ahmmed Razu
Advanced Member level 4
- Joined
- Jul 7, 2011
- Messages
- 100
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,298
- Location
- Bangladesh
- Activity points
- 1,968
I am trying to make SPI communication EEPROM X25128P(25C128 in Proteus) with atmega8. But i failed to do that.I can not understand where i have made mistake.I am using mikroC compiler.My code is given following...
corrected code of another compiler(like avrstudio then ok).Suggest me.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 sbit Chip_Select at PORTB0_bit; sbit Chip_Select_Direction at DDB0_bit; unsigned int buffer=0,value=0; void Init() { DDRD=0xFF; PORTD=value; Chip_Select = 1; // Deselect DAC Chip_Select_Direction = 1; // Set CS# pin as Output //SPI1_Init(); // Initialize SPI1 module SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV64, _SPI_CLK_LO_LEADING); Delay_ms(2000); } void spi() { chip_Select=0; //write latch enable SPI1_write(0x06); //enable write enable latch chip_Select=1; Delay_ms(10); //write status register chip_Select=0; SPI1_write(0x01); //instruction to write in the status register SPI1_write(0x02); chip_Select=1; Delay_ms(10); chip_Select=0; //start of write operation SPI1_Write(0x02); //instruction code to write in the EEPROM SPI1_Write(0xC001); SPI1_write(0x04); chip_Select=1; Delay_ms(10); chip_Select=0; //start of read operation SPI1_Write(0x03); //instruction code to read in the EEPROM SPI1_write(0xC001); value=SPI1_Read(buffer); chip_Select=1; PORTD=value; } void main() { Init(); while (1) { Delay_ms(1000); spi(); } }
corrected code of another compiler(like avrstudio then ok).Suggest me.
Last edited: