SPI chip select question

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SPI chip select question

2,566件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Wed Jun 29 20:13:16 MST 2011
I have been trying to get SPI on a 1343 to work in slave mode with a frame of bytes but I can't seem to get it to work.

I can get a single byte by pulling CS low, byte, CS high.
But I want to go CS low, byte, byte, byte, byte, CS high.
So the data can be sent as a frame.

My current code issues this function in the main loop, and I am using a BusPirate to send the data to the 1343.
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [B]SPIR3[/B](){
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](LPC_SSP->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &(1<<2)){
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](LPC_SSP->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & (1 << 4));
getMessage[globaltest] = LPC_SSP->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
globaltest++;
}
[/LEFT]
}
[/SIZE]

And this works for a string with each byte wrapped with a chip select...

And ideas what I am doing wrong?

Thanks
Dave
0 件の賞賛
返信
9 返答(返信)

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elef on Mon Dec 26 21:13:56 MST 2011

Quote: Dave3891
I have been trying to get SPI on a 1343 to work in slave mode with a frame of bytes but I can't seem to get it to work.

I can get a single byte by pulling CS low, byte, CS high.
But I want to go CS low, byte, byte, byte, byte, CS high.
So the data can be sent as a frame.

Thanks
Dave



Dave,

Did you get this working?
According to the User manual, you can do it as long as your CPHA is 1. You should be able to transfer 1 word or multiple words (ie 4 in your case, or as many as you want, it is arbitrary) without SSEL (CS) changing. This would make sense when reading serial SPI flash chips, as you would be reading millions of bytes in one hit, without changing SSEL (CS).

cheers.
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Dec 02 08:13:11 MST 2011

Quote:

But i want to use this pin as a SSP SSEL pin and try to set it to low as it is idle. Is this possilbe ? (You have told me that it is not supported)

No, it's not possible :mad: How SSEL/CS is working with different modes is shown in UM. There's no bit which could be set to invert SSEL/CS.
So the usual solution is to generate this signal with GPIO and set/reset it before/after SSP transmission (e.g. for driving 2 or more slaves with 1 SSP).
If you want to use an 'inverted' SSEL, you have to invert it by additional hardware  :)
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Chaoyin on Fri Dec 02 07:09:59 MST 2011

Quote: Zero
Of course you don't get a GPIO if you set SSEL pin function :eek:

LPC_IOCON->PIO0_15 &= ~0x07; //SSP I/O config
LPC_IOCON->PIO0_15 |= 0x02; [COLOR=red]//pin function 2: SSP CS [/COLOR]
GPIO would be:
LPC_IOCON->PIO0_15 &= ~0x07; //SSP I/O config
LPC_IOCON->PIO0_15 |= 0x00; [COLOR=red]//pin function 0 = GPIO [/COLOR]
Then you can set direction to output and clear/set this GPIO pin

Note: There's also a hardware solution: invert your SSEL signal :rolleyes:


Hi Zero,
thanks again.  I can understand what you mean. with your explain man can use this pin (PIO0_15) as a GPIO pin for example:
[SIZE=2]    LPC_GPIO0->[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DIR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= (1 << 15);   [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set this Pin as Output[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2]    LPC_GPIO0->[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SET[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= (1 << 15); // set it to high[/SIZE]

[SIZE=2]    LPC_GPIO0->[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CLR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= (1 << 15); // clear/set it to low[/SIZE]

[SIZE=2]But i want to use this pin as a SSP SSEL pin and try to set it to low as it is idle. Is this possilbe ?  (You have told me that it is not supported)  Please see the following [/SIZE]
[SIZE=2]descriptive writing.[/SIZE]


[SIZE=2]     Idle status "Low"                          ---------------------------------                          Idle status "Low" [/SIZE]
[SIZE=2]------------------------------------        data Transmission ("High")             -------------------------------                     [/SIZE]
[SIZE=2]It's very kind of you to help.[/SIZE]

[SIZE=2]Yin[/SIZE]
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Dec 02 06:49:14 MST 2011

Quote:

...but i could not get the right result.

Of course you don't get a GPIO if you set SSEL pin function :eek:

LPC_IOCON->PIO0_15 &= ~0x07; //SSP I/O config
LPC_IOCON->PIO0_15 |= 0x02; [COLOR=Red]//pin function 2: SSP CS [/COLOR]
GPIO would be:
LPC_IOCON->PIO0_15 &= ~0x07; //SSP I/O config
LPC_IOCON->PIO0_15 |= 0x00; [COLOR=Red]//pin function 0 = GPIO [/COLOR]
Then you can set direction to output and clear/set this GPIO pin

Note: There's also a hardware solution: invert your SSEL signal :rolleyes:
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Chaoyin on Fri Dec 02 06:29:23 MST 2011

Quote: Zero
Why?  That's unusual and therefore not supported. But, of course you can use SSEL pin as GPIO pin (see PINSEL registers) and switch it in your SSP/SPI code :)



Hallo Zero,

thank you very much for your reply. I need set my SSEL low for the idle status because of the requirement of the slave setting (i can not change the slave setting). I get the SSEL low for the data transmission by using the following code
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// SSP SSEL (page 100) -- need be configured: "0" = active, "1" = inactive![/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[SIZE=2]LPC_IOCON->PIO0_15 [/SIZE]&= ~0x07;             [COLOR=#3f7f5f]//SSP I/O [U]config[/U][/COLOR]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE]LPC_IOCON->PIO0_15 |= 0x02;          [SIZE=2][COLOR=#3f7f5f]//SSP CS[/COLOR][/SIZE]     
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]In order to fillful my need will be utilized the following code:[/SIZE][SIZE=2][SIZE=2]


LPC_IOCON->PIO0_15 |= 0x02;          [SIZE=2][COLOR=#3f7f5f]//SSP CS[/COLOR][/SIZE]     [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]LPC_GPIO0->DIR |= (1 << 15);    // Set this Pin as Output
[/COLOR][/SIZE][/COLOR][/SIZE][/SIZE][SIZE=2] LPC_GPIO0->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CLR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= (1 << 15); // set it to low[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]but i could not get the right result. Could anyone help me out?[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]thanks[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]Yin

[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE]
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Dec 02 05:21:39 MST 2011

Quote: Chaoyin
...want to set SSEL " low"  for the idle status and "high" for the data transmission



Why?  That's unusual and therefore not supported. But, of course you can use SSEL pin as GPIO pin (see PINSEL registers) and switch it in your SSP/SPI code :)
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Chaoyin on Fri Dec 02 04:59:07 MST 2011
Hallo  everyone,

i am using lpc1227 and want to set SSEL " low"  for the idle status and "high" for the data transmission. But i can measure the SSEL "low" for the data transmission with an oscilloscope.

In the user manual (UM10441) i find the Description for SSEL: the active state of this signal can be high or low depending upon the selected bus and mode.

Could anyone kindly tell me how to do it?

Thanks a lot

Yin
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Thu Jun 30 06:16:05 MST 2011

Quote: Zero
Are we talking about SPI and SSEL?


Yes.

I guess I will have to use I2C then since I wanted to use the SSEL as my frame start/end condition and if I have to pulse it after every byte, it will not work well for me.

Thanks
Dave
0 件の賞賛
返信

2,330件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jun 30 00:54:07 MST 2011
Are we talking about SPI and SSEL?
User manual:

Quote:

In the case of a single word transmission, after all bits of the data word have been transferred, the SSEL line is returned to its idle HIGH state one SCK period after the last bit has been captured.
However, in the case of continuous back-to-back transmissions, the [COLOR=red]SSEL signal must be pulsed HIGH[/COLOR] between each data word transfer. This is because the slave select pin freezes the data in its serial peripheral register and does not allow it to be altered if the CPHA bit is logic zero.
Therefore the master device must raise the SSEL pin of the slave device between each data transfer to enable the serial peripheral data write. On completion of the continuous transfer, the SSEL pin is returned to its idle state one SCK period after the last bit has been captured.

0 件の賞賛
返信