Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

New to SPI - SRAM interfacing with PIC18 in Proteus

Status
Not open for further replies.

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:
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)

spidbg.PNG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top