I am into a project where I need 2 establish communication between ADuc814(Master) and ADuc841(Slave). Master shud Receive data transmitted by Slave. I am unable to establish the comm. I feel there is no response 4rm slave as though master generates the clock and SS pin is low, slave does not response. Is it necessary that both master and slave should operate in same CLOCK?? For Hardware connection, MOSI, MISO, SCLK and SS pins of Master and Slave are connected. Foll is the code Master Code
#include <ADUC814.H> unsigned char Data[20]; //Store SPI Rx data in Memory void Uart_Tx(unsigned char AsciData); //Serial Tx sbit SS = 0xB5; void main() { char i; PLLCON = 0x00; //Core Clk = 16.6777MHz //////////baud 0f 4800//////// RCAP2H = -1; RCAP2L = 0x92; TH2 = -1; TL2 = 0x92; SCON = 0x50; T2CON = 0x34; ////////////////////////////// CFG814 = 0x01; // Enable P3.5,6,7 for SPI SPICON = 0x37; // Master, CPOH=1,CPOL=0 SS = 0; // Slave Select Enable for(i=0;i<20;i++) { SPIDAT = 0x00; // SPI Clock Generate while(!ISPI); ISPI = 0; Data[i] = (unsigned char)SPIDAT; } /////////Serial Tx SPI Data into UART////////// for(i=0;i<20;i++) { Uart_Tx(Data[i]); Uart_Tx('\n'); } ///////////////////////////////////////////// }
Slave Code, ADuC841
void main() { char i; SPICON = 0x24; // Slave, CPOH=1, CPOL=0 for(i=0;i<20;i++) { SPIDAT = 0x38; /*Transmit Dummy Data, Asci of '8' while(!ISPI); ISPI = 0; } }
Friendzzzz Please Help.........
make all replies at http://www.keil.com/forum/docs/thread11431.asp
this is a double post, it will get totally confoosing if the replies get 'distributed'.
Erik
It would be better to reply in this thread - as the code posted in the other one is illegible.
Of course, rather than create a new thread, it would have been more sensible if Jaydeep Krishna had just updated the original one.
Or, having created a new one, if he had at least put a note in the old one to explain!
This code isn't legible either.
Where does the following comment end?
{ SPIDAT = 0x38; /*Transmit Dummy Data, Asci of '8' while(!ISPI); ISPI = 0; }
and why:
while(!ISPI); ISPI = 0;
instead of:
while (!ISPI) ; ISPI = 0;
so that it is clearly visible that the while loop is empty, and that the assign is expected to be made after the while loop ends?
{ SPIDAT = 0x38; /*Transmit Dummy Data, Asci of '8'
Instead of the magic number, why not write '8' and remove the need to comment:
{ SPIDAT = '8'; // Transmit Dummy Data
More useful as a comment would be why '8' was chosen...
//////////baud 0f 4800////////
This use of '/' looks very dodgy - it's relying upon the compiler taking the first two as a "//" comment-introducer, but then not complaining about the next two as a nested comment...
There are no nested comments with '//', since there are no sequence to reduce the nesting level.
And since '//' isn't a keyword, there are no requirements about white-space and separators for it. A compiler who do support the C++ one-line comments are required to ignore any character until end-of-line as soon as it has seen the two-character start token.
Writing ///////// text /////// is just as ok as using the classic C method /******* text *******/ (still with the restriction that not all C compilers supports the C++-introduced one-line comments.
Hi buddy, I value ur comments, bt all the code comments were written just as additional xplanation. I do not intend 2 offend any1s intelligency. Bt it seems d attention got diverted 2 all the various comments instead of the main question. Thts a sad part. Furthr some codes were put on same line bcause of allignment probs while postin. If this clarifies all d doubts or inconvenience, I wud appreciate some suggestions 2 the main problem.
Thnxxxx in advance.
"Thnxxxx"
That must have taken quite some effort -- adding three more X's than required. With so much extra effort, you have demonstrated your eagerness and a keen desire for the help you seek. It almost makes up for all the shortcuts you have posted and key information you have not posted.
You have qualified for a free fortune cookie:
"You will be equally rewarded for your efforts and you will become a rich man with many wives."
would have been far better spent writing proper words, instead of all that stupid SMS abbreviation nonsense!
"I do not intend 2 offend any1s intelligency"
Are you acually typing this on a mobile phone keypad?
If so, fair enough; but if not, that in itself is an offence to anyone's intelligence!
If you have a proper keypad, then type proper words - stop all this cryptic abbreviation!
The language barrier is bad enough as it is, without having to wade through this nonsense.
I do not intend 2 offend any1s intelligency then why do you do so with this gibberish ?
SPI uses one master clock: derived from the master uC. There is no need to 'sync' the master & slave uC oscillators.
NOTE: Assuming that your slave is not radically below its minimum operational frequency, then the slave's internal state machine should be capable of shifting in the master's bits, using the master's clock signal.
You should identify what you have already done during your testing of the system...
Are you sure that the Master's MOSI is connected to Slave's MISO, etc? (double-check it).
Did you see the Master's clock on a scope? was it good?
Was the master's data also valid?
What did the slave's data look like?
Are your voltage levels okay? (Slave's thresholds consistent with Master's? --- I don't want to look up those device data-sheets just yet).
I do not know about AD, but for the SILabs uCs hardware SPI engines you connect MOSI to MOSI and MISO to MISO. That makes sense to me.
MOSI = Master OUT, Slave IN (Master to Slave data direction) MISO = Master IN, Slave OUT (Slave to Master data direction)
So unless the SILabs uCs have some sort of software control on the data direction, I'm guessing you might be mistaken.
Oh, I get it ... sorry! Yes. Erik. You are right. Thats what I meant.
The point is to make sure that the data direction is correct.
I have properly connected Masters MOSI, MISO, SS and SCLK to corresponding lines of Slave. I have also checked the clock on scope. The master (ADuC814) generates clock properly as per the program logic. Even SS pin is low throughout. Bt still no communication happens btween them. I changed the slave to ADuC814(earlier ADuC841), and made master transmit the data 2 slave and slave does UART o/p. This works absolutely fine. Here both master and slave operated at same core clock 16.67MHz.Then I changed the slave core clk to 8.3 MHZ, keeping master at 16.67MHz. This time some blanks appeared in between the output (I chkd on HyperTerminal). Don't know why?? Got 2 figure it out. But still I got some output on HT. However with ADuC841 as slave and slave is made to transmit the data to master(ADuC814), though I am able to see the SCLK that master generates, the MISO line of slave remains high always. Always blanks get printed on HT. This is what I am not able to get it?? The slave core clock is 11.0592Mz and master operates at 16.67MHz. Could there be some synchronization problem like rising edge of master and slave might be different due to different core clock??