Hi everybody !
I'm currently working on a project with a ADuC847 and I would like to copy the content of SBUF (data register of UART) to SPIDAT (data register of SPI). Here is a part of my code:
T3CON = 0x83; //9600 Baud rate
T3FD = 0x12;
SCON = 0x52; // UART enable, variable baud rate.
SPICON = 0x2C; // SPI enable, slave mode
while(!RI); //interrupt flag of UART (Set when SBUF is full)
if(ISPI==0 && RI==1)
{ SPIDAT = SBUF; // This line doesn't work. Value is still egual to 0
value = SPIDAT; }
RI = 0; ISPI = 0;
Someone would have any idea ? thanks in advance,
Guillaume.
Because I've put variables in order to see what values take SPIDAT and SBUF and what I can see is that SBUF is different from SPIDAT which is always equal to 0. But I have a track. When I display the value of SBUF (normally a 8-bit register) I can see values ranging from-30720 to 30720 ... I absolutely don't know why. That's why I guess, SPIDAT is still always equal to 0. What do you think ?
Because I've put variables in order to see what values take SPIDAT and SBUF and what I can see is that SBUF is different from SPIDAT which is always equal to 0. how do you 'see' them?
But I have a track. When I display the value of SBUF (normally a 8-bit register) I can see values ranging from-30720 to 30720 ... I absolutely don't know why. That's why I guess, SPIDAT is still always equal to 0. What do you think ?
0d30720 - 0x7800 again WHAT are you using to 'see' the variables?
Erik
unsigned char a;
while(!RI);
{
a = SBUF;
SPIDAT = a;
value = 2;
}
RI = 0;
ISPI = 0;
//send data to base station
sprintf(message, "SBUF= %d & SPIDAT = %d", a, SPIDAT);
That's my way to see the value of the registers. I don't understand why the values of SBUF ranging from 30720 to -30720 (decimal numbers). unsigned char are normally included between 0 and 255... Like I said, SBUF & SPIDAT are both 8-bit registers.
by the way, thanks a lot to try to help me :) I appreciate.
Note that these data registers for peripherials are normally a read-only register overlapped with a write-only register. So when you write a value to a data register, you can't expect to then read back and see your written value.
Why don't you trust the processor? If your UART says it has a byte available for read, and your SPI device says it is ready to accept one more write, then you should have a good chance of being able to read from the UART, and write to the SPI, shouldn't you?
When copying from UART to SPI, it's important that the SPI is running at high enough speed - or you would need to use XON/XOFF or handshake signals on the UART side to pace the transfer.
Your remark is correct! there are two data register physically separated. therefore it's normal that the value I wrote in SBUF was different of the value I read. So do you think that SPIDAT = SBUF is correct ?
"So do you think that SPIDAT = SBUF is correct ?
Have you found any errata for the processor saying that the UART is broken, and that it isn't possible to read from SBUF?
Have you found any errata for the processor saying that the SPI device is broken, and that it isn't possible to write to SPIDAT?
Exactly why do you question the possibility of reading from SBUF or writing to SPIDAT? Do you think the UART have special tracking to know where the data read from it is sent? Do you think the SPI device has special tracking that checks where the data to send comes from?
Don't you think you should take two steps back and find other ways to figure out why your code and/or hardware doesn't work as expected, than questioning if the processor has a serious design issue?
I'm not telling that the processor has a serious design issue ! But I have to send data which come from the UART and send them via the SPI. I just want to create a "link" between UART and SPI. I guess that I have to do this with the two data registers SBUF and SPIDAT. I'm right? I absolutely do not question the processor.
For information, the hardware work well, it's an Analog Devices kit (EVAL-ADF70xxMBZ2). The problem is certainly my code!