SPI HELP DESPERATE
hi there,
I just can't get the SPI working, this is what i do, please help!:
I am using SPI between a dsPIC30F4013 and the ADE7753. So i setup the dsPIC as master mode(which works, as i have used it successfully to communicate to another dsPIC in slave mode). After setting up the dsPIC to master mode and enabling the SPI, i send data to the ADE to tell it that i am going to write to it. So, if i want to write to the test register for example, i would first send the byte,0xBD, this i assume goes automatically to the communications register. then i test the dsPIC's tx register flag to see if it has sent the data already, once its empty i wait 4microseconds, then i send the data i would like to write to it.
Looking on an oscilloscope, the transmitted data of the dsPIC works fine. the problem comes in, when i read the data. I do exactly the same process, only now i send the communications register 0x3D(since i want to read back the value i have just written to the test register), then i wait 4microseconds and i wait until the recieve buffer of the dsPIC is full and then i read the bytes by putting the bytes onto a PORT with LED's on it, just to see if i have recieved the same bytes i have written to the register. I do all of the above in a while loop so that i can also see it on the oscilloscope, but the read part goes mad. It keeps giving me different readings back. like, if i say send the gain register 0x73 then it will send different stuff back each times, i can see how the LED's change.
i have a feeling this has to do with the timing, im also still not sure if i have to read the rx buffer of my dsPIC after each sent data to the ADE. but i have tried so many different things and im quite in despair now. I changed clock polarity and whether or not the master should send data at rising or falling edge, but it seems that i cant get the right combination and its driving me insane having an idea of what it is, but not getting it right!! please help.
also, is it ok if the hardware is only connected to ground and 5V and the rx,tx,clk,cs is connected directly to the dsPIC, should i use pull up/down resistors on the SPI pins of the ADE??it could also be this that is not stabalised, i must still try that. let me know what you think.Also, is the test register a special register mad to send data to it so that one can test the way i am? bec i even tried different registers just incase.
regards