- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Guys,
I am having some trouble with the SPI. I have looked through the site and found some documents but not a worked example.
The code is ported across from a Microchip project. The Devie is PSOC 5LP and the memory is FM25W256-G.
The code runs until the second line in the ReadByte routine and appears to hang. I have the SPI component set to Mode 0 and 4MHz using internal clock source. Does my code below look correct? Or is there something I need to enable or initialise? Thanks in advance for your help.
#define WREN 0x06
#define MEMWRITE 0x02
#define MEMREAD 0x03
unsigned char Muted;
unsigned char testbyte;
void SendByte(unsigned short MemAddress, unsigned char MemData) //FM25W256-G Device
{
MEM_EN_Write(false); //Enable Write function
SPI_WriteByte(WREN);
MEM_EN_Write(true);
MEM_EN_Write(false); //Send Write command
SPI_WriteByte(MEMWRITE);
SPI_WriteByte(MemAddress >> 8); //Send 16-bit Address, MSB first
SPI_WriteByte(MemAddress);
SPI_WriteByte(MemData); //Send Data byte
MEM_EN_Write(true);
}
unsigned char ReadByte(unsigned short MemAddress)
{
unsigned char i;
MEM_EN_Write(false); //Send Read Command
SPI_WriteByte(MEMREAD); //************************ LOCKS UP on this line ********************
SPI_WriteByte(MemAddress >> 8); //Read Address, MSB fist
SPI_WriteByte(MemAddress);
i = SPI_ReadByte(); //Read the byte ????
MEM_EN_Write(true);
return i;
}
void init(void)
{
CyGlobalIntEnable;
PWM_Start();
SPI_Init();
}
int main()
{
init();
SendByte(0x01, 0x33);
testbyte = ReadByte(0x01); //Test byte should = 0x33
for(;;) {}
- Labels:
-
ispn:37278:1:0
-
l1:4041:1:0
-
l2:4043:1:0
-
PSoC5LP