Hi there.
Are there any application notes on how to use SPI with a device like M30245?
I am missing the CS line? Do I have to manage that in software or is it possible to do the hardware the job?
regards
luke
http://home.arcor.de/luka5/open/SPI_01.GIF
You can see the data send througt the TxD line (2. in picture): 0x8000
I am wondering why there is a "ONE" at LSB´s position because I am writing 0x00 to the u3tbgl register twice..
1.RxD
2.TxD
3.!CS
4.Clock
No matter what I do, there always a "ONE" at the firts postition.
When I do this:
CS = 0;
te_u3 = 1;
while( !ti_u3);
u3tbl = 0xFF; // <--- first 8 bits
while( !ti_u3);
while( !txept_u3);
u3tbl = 0x00; // <--- last 8 bits
while( !ti_u3);
while( !txept_u3);
re_u3 = 0;
te_u3 = 0;
ckpol_u3 = 1;
CS = 1;
ckpol_u3 = 0;
I get this at the TxD line: 0xFF80;
It seems that first a "ONE" is send, then the 0xFF and finally this: 0b0000000 (7 bits only)
The result of that 16-bit write: u3tb = 0x0000;
is the following: 0x80; at TxD (only 8 clocks)
If I write: u3tb = 0xFFF0:
result is: 0xF8; (only 8 clocks)
It seems, to me that there is always a "ONE" shifted in.
This is how I have set up the SPI mode:
u3smr = 0x00; // No I2C Mode
u3smr2 = 0x00;
u3smr3 = 0x00; // SS Port function.. ??
u3smr4 = 0x00;
u3mr = 0x01; // SPI MODE, Internal Clock
u3c0 = 0x92; // Data on falling edge, f32 as clock source, no CTS, CMOS output
u3c1 = 0x00; // rx,tx disabled
u3brg = 0xff; // (Takt UART3) very slow..
I am using a m30245fcgp.
There is no application note on SPI for this µC nor even for this family: M16C/24
I have found some document describling the SPI for a M16C/6P i think, I am not sure about that type.
The SPI hardware should be the same as for the M16C/24. Someone here wrote it.
Nethertheless the datasheet should be enough to configure the SPI mode..
Sorry, I got carried away as the u3smr registers are listed only in one figure.
Have you tried to set the registers manually and see what is transmitted?
I did so, and I dfon't have a problem with the first bit. THe TxD line keeps the state of the last bit. So I send 0x0F. Then I see that the first 4 bit are 0, the second 4 bit are one.
This is what I´ve observed:
The first diagramm was recorded with a setup "data on rising edge"
The second one with "data on falling edge"
The value I am transmitting is: 0x36
I dont think they differ at all...
http://home.arcor.de/luka5/open/rising.GIF
http://home.arcor.de/luka5/open/falling.GIF
Both times it concerns only the TxD3 line because the RxDi lines are reversed (data on rising edge on TxDi --> data on falling edge on RxDi).
If signals on rising and falling edge are the same you have a problem with the UART initialisation.I also transmit 0x36 once on rising and once on falling edge. You can see the shift immediately.
http://www.renesasrulz.com/servlet/JiveServlet/downloadBody/1531-102-1-1444/DifferentEdgeSignal.zip
And what do you mean by RxD lines are reversed. It is correct that if TxD shifts data out on falling edge, then RxD has to read on rising edge. BUt for the register settings, this is exactly the same setting. If TxD is set to change output data on falling edge, this implies that RxD reads data on rising edge and vice versa.
After reading that again I understand that You are confused with that: "RxD lines are reversed"
It is my mistake. Of course I did mean it just like You explained it.
According bad initialization of the UART.. What inti do You use?
Am using the KD30 too.
I dont know how to set the register directly.
If I try to write a value at the adress 32A using the memory window the new value will not be set the old value remains.
The transmit buffer (address 0x32A) is a bad example as this register is write only. I wrote the values you mentioned earlier:
- 0x01 to address 0x328 (u3mr)
- 0x92 to address 0x32C (u3c0)
- 0x01 to address 0x32D (u3c1)
- 0xFF to address 0x329 (u3brg)
and then for transmit I only write 0x36 to address 0x32A (as 8 bit value which works fine).
To change transmit polarity I write 0xD2 to 0x32C.
Just note that some bits are read only bits like transmit buffer empty flag or transmit register empty flag not all values will change as you write them.
Ok, now I know what was wrong.
Namely: the datasheet.
The datasheet claims, that a CKPOL = 0 in the UiC0 register sets the SPI up, to clock out data at falling edge.
If CKPOL = 1 data is clocked out at rising edge.
Thats wrong because its the opposit of how it behaves with my MCU.
So CKPOL = 0 -> rising edge.
CKPOL = 1 -> falling edge.
Can You proof that?
regards
luke
Ok. Here I am again with that issue..
Using the Hardware SPI with a M16C24 (M30245FCGP) I observed strange behaviour.
void SPI3_init( void)
{
pd2_3 = OUT; // ADC_CD is OUT
pd7_6 = OUT; // ADC_CLK is OUT
pd7_5 = IN; // ADC_DOUT
pd7_4 = OUT; // ADC_DIN
ADC_CS = HIGH; // ADC communication disabled [ Chip Select]
u3c0 = 0xD1; // MSB first, falling edge, CTS disabled, internal Clock f8 (2MHz)
u3c1 = 0x00; //
u3brg = 1999; // divide f8 by 2000
u3c0 &= ~0x20;
u3smr3 &= ~0x02;
u3mr = 0x01;
ckpol_u3 = 0; // transmit data is output at falling edge, recieve data is input at rising edge of clk
}
The code above should normally configure uart3 to transmit data at falling clk edge.
What I am observing is the opposite.
In the following scope screenshot one can see, that data is output at rising edge. (I am writing: 0b0101 0101 0000 1111)
http://home.arcor.de/luka5/open/M16CSPI/ckpol-0.jpg
And here a zoom in at the first falling edge where data should be: 0
http://home.arcor.de/luka5/open/M16CSPI/ckpol-0_b.jpg
In best case both transitions, DATA and CLK occur simultanously. This results in a undefined state.
In worst case CLK falls when DATA is still HIGH.
My reciever (a ADC) has a DIN set-up time prior to SCLK falling edge of min. 4ns.
And a DIN hold time after SCLK falling edge of min. 2ns
Now I show you a screenshot with ckpol_u3 = 1; [The datasheet says: if ckpol_u3 = 1, Transmit data is output at rising edge, recieve data ist input at falling edge of clk]
http://home.arcor.de/luka5/open/M16CSPI/ckpol-1.jpg
Zoom in of the first rising edge:
http://home.arcor.de/luka5/open/M16CSPI/ckpol-1_b.jpg
In my opinion this is a transmission on rising edge not on falling edge.
What do you think about it?
Regards
luke
©2003–2010 Renesas Technology Corp. All rights reserved. Using Our Website | Privacy
Contact us