Anonymous
Not applicable
Jan 14, 2010
03:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 14, 2010
03:01 PM
I spent hours on the SPI interface and still couldn't get it work.
The program is very simple, I use a SPI mater talking to a SPI slave device. The device responsed one byte of data, but I couldn't get it from the SPIM_1_bReadRxData() function.
while(1)
{
output_low(port0,pin6); //Set the chip select /CS
txdata = 0x8F; //Slave device register
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
SPIM_1_SendTxData(txdata); // send the read command
SPIM_1_SendTxData(0xA3); // send the dummy byte to clock the rx data from the slave device
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
rxdata = SPIM_1_bReadRxData(); // read the first byte , dummy data generated by the first byte sent
PRT1DR = rxdata; // put it on port 1 so I can see the data;
rxdata = SPIM_1_bReadRxData(); // read the real data
PRT2DR = rxdata; // put it on port 2 so I can see the data;
output_high(port0,pin6); //Set the /CS to high
}
I set up all the I/O ports, operating mode 0 correctly, I can see all the data lines and the slave device responsed correctly on a scope too.
But the port 1 and 2 do not equal to the rx data. In fact, all lines are low. When I just remove the MISO line, the lines go high because of the pull-up on the MISO line. Meaning it read something, but not the data from the slave device
Any body can help? Can't find any good examples on the SPI bus and the example from Cypress is very poor.
Thanks.
The program is very simple, I use a SPI mater talking to a SPI slave device. The device responsed one byte of data, but I couldn't get it from the SPIM_1_bReadRxData() function.
while(1)
{
output_low(port0,pin6); //Set the chip select /CS
txdata = 0x8F; //Slave device register
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
SPIM_1_SendTxData(txdata); // send the read command
SPIM_1_SendTxData(0xA3); // send the dummy byte to clock the rx data from the slave device
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
rxdata = SPIM_1_bReadRxData(); // read the first byte , dummy data generated by the first byte sent
PRT1DR = rxdata; // put it on port 1 so I can see the data;
rxdata = SPIM_1_bReadRxData(); // read the real data
PRT2DR = rxdata; // put it on port 2 so I can see the data;
output_high(port0,pin6); //Set the /CS to high
}
I set up all the I/O ports, operating mode 0 correctly, I can see all the data lines and the slave device responsed correctly on a scope too.
But the port 1 and 2 do not equal to the rx data. In fact, all lines are low. When I just remove the MISO line, the lines go high because of the pull-up on the MISO line. Meaning it read something, but not the data from the slave device
Any body can help? Can't find any good examples on the SPI bus and the example from Cypress is very poor.
Thanks.
Labels
- Labels:
-
PSoC 1
1 Reply
Anonymous
Not applicable
Feb 24, 2010
03:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 24, 2010
03:26 AM
Hey..
Did you find the problem? If not... maybe you should first see if it get's out of the while loops using a pin. See like below.
while(1)
{
output_low(port0,pin6); //Set the chip select /CS
txdata = 0x8F; //Slave device register
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
PRT1DR ^=0x01;
SPIM_1_SendTxData(txdata); // send the read command
SPIM_1_SendTxData(0xA3); // send the dummy byte to clock the rx data from the slave device
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
PRT1DR ^=0x02;
rxdata = SPIM_1_bReadRxData(); // read the first byte , dummy data generated by the first byte sent
PRT1DR = rxdata; // put it on port 1 so I can see the data;
rxdata = SPIM_1_bReadRxData(); // read the real data
PRT2DR = rxdata; // put it on port 2 so I can see the data;
output_high(port0,pin6); //Set the /CS to high
}
Did you find the problem? If not... maybe you should first see if it get's out of the while loops using a pin. See like below.
while(1)
{
output_low(port0,pin6); //Set the chip select /CS
txdata = 0x8F; //Slave device register
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
PRT1DR ^=0x01;
SPIM_1_SendTxData(txdata); // send the read command
SPIM_1_SendTxData(0xA3); // send the dummy byte to clock the rx data from the slave device
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL)) {};
PRT1DR ^=0x02;
rxdata = SPIM_1_bReadRxData(); // read the first byte , dummy data generated by the first byte sent
PRT1DR = rxdata; // put it on port 1 so I can see the data;
rxdata = SPIM_1_bReadRxData(); // read the real data
PRT2DR = rxdata; // put it on port 2 so I can see the data;
output_high(port0,pin6); //Set the /CS to high
}