SPI_READ() problem

Status
Not open for further replies.

tattee

New Member
Hi,

I am currently using PIC16F873 and CMX868 modem communicating through SPI. I got the SPI_Write to work perfectly but I had problems on SPI_READ routine.

here is how the operation goes:
1. PIC send DTMF tones(HEX) to the modem via SPI
2. modem decode the DTMF ang send out to speaker with the corresponding tone
3. modem accepts acknowledgement through a microphone(attahced to the modem) in the form of an audio tone
4. sends the audio tone to the PIC via SPI for verification
5. PIC decides what to do.

procedure 4 is where I get the problem. please see the datasheet below and look at page 27. Bits0-3 are the data I have to read.

http://www.datasheetcatalog.org/datasheet/CML/mXxtwts.pdf
 
An SPI slave cannot send data to the Pic, the Pic has to request the data. I think you need to send 0xe6 and then two dummy bytes. When the dummy bytes are sent you should receive the 16 bit status register.

Mike.
 
Yeah, that's what I did. here is the program I have for that part.

Code:
void Dtmf_Receive()
{
  unsigned short take, take2, take3;  

  CS_MODEM = 0;
  Spi_Write(0xE6);
  Spi_Write(0);
  Spi_Write(0);
  CS_MODEM = 1;

  take = Spi_Read(0);

  take2 = take & 0b00001111;            //mask bits 4-7
  take3 = take2 ^ 0b00001101;          //is the recieved tone "A"? (A = 0xD)

  if(take3 == 0)

    //do something here

}
 
Last edited:
I think what you need is,
Code:
  CS_MODEM = 0;
  Spi_Write(0xE6);
  take = Spi_Read(0);
  take2 = Spi_Read(0);

Mike.
 
that worked! Great! I've been working 3 days now for this thing.
Code:
void Dtmf_Receive()
{
  CS_MODEM = 0;
  Spi_Write(0xE6);
  take = Spi_Read(0);
  take2 = Spi_Read(0);
  CS_MODEM = 1;

  take3 = take2 & 0b00001111;
  take4 = take3 ^ 0b00001101;
  if(take4 == 0)
    //do something here

}
 
Glad to hear it worked.

Edit,
Do you realize, you can do,
Code:
  if(take2 & 0x0f == 0b00001101)
    //do something here
and miss out the two lines before.

Mike.
 
Last edited:
Yeah, that will do! i'l try to shorten my codes. Im still not finished with my project, im now working on the EEPROM. Hopefully, I could make things work.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…