Synaps3
Member level 1
- Joined
- Oct 14, 2014
- Messages
- 37
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 358
I'm trying to interface an SPI SRAM chip with a PIC18F4685 in Proteus. The data appears to be sent if I look at the SPI debugger, but right after that there is a receive with ?? and Proteus returns "Unrecognized command code [00]". Right now I'm only trying to write. I will later implement the read.
I've attached an image of the SPI debugger. You can see in the debugger command = 2, address = 0x0a01, and data = 0xBB. This is correct, but what is this error after?
My code in mikroC:
I've attached an image of the SPI debugger. You can see in the debugger command = 2, address = 0x0a01, and data = 0xBB. This is correct, but what is this error after?
My code in mikroC:
Code:
// SerialRAM connections
sbit Chip_Select at RC7_bit;
sbit HOLD at RC6_bit;
sbit Chip_Select_Direction at TRISC7_bit;
sbit HOLD_Direction at TRISC6_bit;
// End SerialRAM connections
unsigned int i;
unsigned short tmp;
// Write one byte of data to specified address
void Write_Data(unsigned int address, unsigned short dat){
Chip_Select = 0; // Select SerialRAM
SPI1_Write(2); // Write instruction
SPI1_Write(address >> 8); // Sending 16 bits address
SPI1_Write(address);
SPI1_Write(dat); // Writing one byte of data
Chip_Select = 1; // Deselect SerialRAM
}
// Read one byte of data from specified address
unsigned short Read_Data(unsigned int address){
Chip_Select = 0; // Select Serial RAM
SPI1_Write(3); // Read instruction
SPI1_Write(address >> 8); // Sending 16 bits address
SPI1_Write(address);
tmp = SPI1_Read(0); // Read one byte of data
Chip_Select = 1; // Deselect SerialRAM
return tmp;
}
void InitRAM() {
Chip_Select_Direction = 0; // Set CS# pin as Output
Chip_Select = 1; // Deselect SerialRAM
SPI1_Init(); // Initialize SPI module
HOLD_Direction = 0; // Set HOLD# pin as output
HOLD = 1;
} // Hold high when this function is not used
void TestRAM()
{
InitRAM();
Write_Data(1 + 0x0A00, 0xBB);
}
(TestRAM is called from main elsewhere)