9S12DG256 - Two SPI module question on HCS12?

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

9S12DG256 - Two SPI module question on HCS12?

3,801件の閲覧回数
AlbertH
Contributor II
Hi, All,
 
I used one SPI module (SPI0) in my HCS12 board, and now it is working.
 
For Some reason, I want to use another SPI module (SPI2) in my board. I use the same idea but different register for SPI2. It is not working.
 
Is there any special thing need to do in using two SPI module in the same HCS12?
 
Thanks in advance.
 
Albert


--
Alban Edit: FSL Part Number must figure in Message Subject line, please.



Message Edited by Alban on 2007-07-25 03:22 PM
ラベル(1)
0 件の賞賛
返信
6 返答(返信)

1,783件の閲覧回数
admin
Specialist II
i haven't used this type of mcu, but when i use dt128, there is a register called "modrr", which is Module Routing Register. this register configures the re-routing of CAN0, CAN4, SPI0 and SPI1 on defined port pins, maybe you should look up in doc's for this one.

for example, in dt128,  the bit5 in this register determines  if the SPI1 is configered in PS4~PS7 or PM2~PM5.

i hope this will help

sorry for bad english
0 件の賞賛
返信

1,783件の閲覧回数
mke_et
Contributor IV
It's been a while and I don't have the code in front of me, but I've used both in a couple of projects, so I know they work. It's been a while, but if I remember right, I just copied the routine from one port to the other and changed the defines and worked fine, so it confirmed that the two are pretty much the same.

If it's not working, first thing I would do is compare your routines for the two.

The second thing I would do is take a good look at all the port definitions. I've bene burnt before where pins are multi-function and use of a pin for certain modes means you have to tickle a setup somewhere else first. I.e. did you set port S for all outputs in the DDR first?

Mike
0 件の賞賛
返信

1,783件の閲覧回数
AlbertH
Contributor II
Thanks all. I fixed this problem long time ago. Sorry for the late response.
 
The problem is exactly as "ToBeNone" said that need to configure the register "MODRR".
 
Thanks again for everybody's help.
 
Albert
0 件の賞賛
返信

1,783件の閲覧回数
AlbertH
Contributor II

I plan to use SPI2 for another TLV5627 for the same function in the same time.

The source code for it is like the following:

void

M3_SPI_Out ( unsigned char Current1_uc, unsigned char Current2_uc )
{
unsigned char SPI_Data_HIGH_Tmp; //SPI out data High
unsigned char SPI_Data_LOW_Tmp; //SPI out data LOW

 if(M3_Current1_Tmp_uc != Current1_uc) //if coil1 current changed 
{
// Motor3 Coil1
PTS &= ~PTS1_msk; //clear pin1 of port S to select SPI for the second TLV5627
SPI_Data_HIGH_Tmp = (unsigned char)(0x10 + ((Current1_uc & 0xF0) >> 4));
SPI_Data_LOW_Tmp
= (unsigned char)((Current1_uc & 0x0F) << 4);
DelayTmp(
20); //delay
PTS &= ~PTS0_msk; //clear pin0 of port S to make FS = 0

SPI2DR
= SPI_Data_HIGH_Tmp; // send the High byte data of SPI Data
while(!(SPI2SR & SPTEF2_msk)); //wait till data transfer finish

SPI2DR
= SPI_Data_LOW_Tmp; // send the Low byte data of SPI Data
while(!(SPI2SR & SPTEF2_msk )); //wait till data transfer finish

PTS
|= PTS0_msk; //SET pin0 of port S to make FS = 1
DelayTmp(20); //delay
PTS |= PTS1_msk; //SET pin1 of port S to deselect SPI for the second TLV5627
M3_Current1_Tmp_uc = Current1_uc;
// }

DelayTmp(
100); //delay

 if (M3_Current2_Tmp_uc != Current2_uc) //if coil2 current changed
 {
// Motor3 Coil2
PTS &= ~PTS1_msk; //clear pin1 of port S to select SPI for the second TLV5627
SPI_Data_HIGH_Tmp = (unsigned char)(0x50 + ((Current2_uc & 0xF0) >> 4));
SPI_Data_LOW_Tmp
= (unsigned char)((Current2_uc & 0x0F) << 4);
DelayTmp(
20); //delay
PTS &= ~PTS0_msk; //clear pin0 of port S to make FS = 0

SPI2DR
= SPI_Data_HIGH_Tmp; // send the High byte data of SPI Data
while(!(SPI2SR & SPTEF2_msk)); //wait till data transfer finish

SPI2DR
= SPI_Data_LOW_Tmp; // send the Low byte data of SPI Data
while(!(SPI2SR & SPTEF2_msk )); //wait till data transfer finish

PTS
|= PTS0_msk; //SET pin0 of port S to make FS = 1
DelayTmp(20); //delay
PTS |= PTS1_msk; //SET pin1 of port S to deselect SPI for the second TLV5627
M3_Current2_Tmp_uc = Current2_uc;
// }
} // End

The initialization for it is like the following:

//for motor3, 4
SPI2CR1 =/*SPIE2_msk + */SPE2_msk/* + SPTIE2_msk */+MSTR2_msk + CPHA2_msk; //SPE bit enable the SPI Module
SPI2CR2 =0;//BIDIROE2_msk; //enable Master out
SPI2BR =0;//0x25; // SPI baud rate = bus clock /32 = 8MHz / 32 .

I measured the output for clock and data out for SPI2 using scope, there is no any output.

Can you any mistake in these source code?  All the register address is correct.

Thanks a lot and Have a great day!

 

Albert

 

0 件の賞賛
返信

1,783件の閲覧回数
Alban
Senior Contributor II
Hello Albert,

Sometimes, the pins have shared functionalities.
Have a look if you need to touch the routing of the port to allow the SPI out.

The Interrupts will be using another vector set as well.

Alban.
0 件の賞賛
返信

1,783件の閲覧回数
AlbertH
Contributor II
Hi, Alban,
 
Thanks for your feed back. I used 9s12DG256. The SPI I already used successfully is SPI0, the pins for it is 93,94, 95,96. I plan to use SPI2, the pins for it is 32, 33, 34, 35. The SPI0 source code is as the following:
 

void

M1_SPI_Out ( unsigned char Current1_uc, unsigned char Current2_uc )
{
unsigned char SPI_Data_HIGH_Tmp; //SPI out data High
unsigned char SPI_Data_LOW_Tmp; //SPI out data LOW

if(M1_Current1_Tmp_uc != Current1_uc) //if coil1 current changed
{
// Motor1 Coil1
PTS &= ~PTS3_msk; //clear pin3 of port S to select SPI for the first TLV5627
SPI_Data_HIGH_Tmp = (unsigned char)(0x10 + ((Current1_uc & 0xF0) >> 4));
SPI_Data_LOW_Tmp
= (unsigned char)((Current1_uc & 0x0F) << 4);
DelayTmp(
10); //delay
PTS &= ~PTS2_msk; //clear pin2 of port S to make FS = 0

SPI0DR
= SPI_Data_HIGH_Tmp; // send the High byte data of SPI Data
while(!(SPI0SR & SPTEF0_msk)); //wait till data transfer finish

SPI0DR
= SPI_Data_LOW_Tmp; // send the Low byte data of SPI Data
while(!(SPI0SR & SPTEF0_msk )); //wait till data transfer finish

PTS
|= PTS2_msk; //SET pin2 of port S to make FS = 1
DelayTmp(10); //delay
PTS |= PTS3_msk; //SET pin3 of port S to deselect SPI for the first TLV5627
M1_Current1_Tmp_uc = Current1_uc;
}

DelayTmp(
50); //delay

if (M1_Current2_Tmp_uc != Current2_uc) //if coil2 current changed
{
// Motor1 Coil2
PTS &= ~PTS3_msk; //clear pin3 of port S to select SPI for the first TLV5627
SPI_Data_HIGH_Tmp = (unsigned char)(0x50 + ((Current2_uc & 0xF0) >> 4));
SPI_Data_LOW_Tmp
= (unsigned char)((Current2_uc & 0x0F) << 4);
DelayTmp(
10); //delay
PTS &= ~PTS2_msk; //clear pin2 of port S to make FS = 0

SPI0DR
= SPI_Data_HIGH_Tmp; // send the High byte data of SPI Data
while(!(SPI0SR & SPTEF0_msk)); //wait till data transfer finish

SPI0DR
= SPI_Data_LOW_Tmp; // send the Low byte data of SPI Data
while(!(SPI0SR & SPTEF0_msk )); //wait till data transfer finish

PTS
|= PTS2_msk; //SET pin2 of port S to make FS = 1
DelayTmp(10); //delay
PTS |= PTS3_msk; //SET pin3 of port S to deselect SPI for the first TLV5627
M1_Current2_Tmp_uc = Current2_uc;
}
} // end

I used TLV5627 as SPI DAC out.

The initilize for SPI0 is

SPI0CR1 = /*SPIE0_msk + */SPE0_msk/* + SPTIE0_msk */+ MSTR0_msk + CPHA0_msk; //SPE bit enable the SPI Module
SPI0CR2 = 0;//BIDIROE0_msk; //enable Master out
SPI0BR = 0;//0x25; // SPI baud rate = bus clock /32 = 8MHz / 32 .

I will use another message to submit.

Albert


 

0 件の賞賛
返信