SPI communication in MC9S12ZVML motor control board

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SPI communication in MC9S12ZVML motor control board

4,438 次查看
ImranAviconn
Contributor II

Hi,

I have initialized the SPI and set its ISR but I could not receive the data and below is my code. The SPI can be set on either PORT S or PORT T and I have set the SPI on both and still it is not working. Below is my sample code for initialization of SPI and its ISR, SPI is set as slave:

void SPI0_init(void){
DDRS = 0X07;
SPI0CR1 = 0xC0;
SPI0CR2 = 0x00;
// SPI0BR |= 0x07;
INT_CFADDR = 0x68;
INT_CFDATA0 = 4;
}

 

INTERRUPT void SPI0_ISR(void){
PTT_PTT1 = ~PTT_PTT1;
rx = SPI0DRL;
}

标记 (2)
0 项奖励
回复
14 回复数

4,408 次查看
ImranAviconn
Contributor II

Hi @danielmartynek 

Thank you for your quick response I have tried that code in my file and its not working. I am editing in codewarrior PMSM source code so that I can communicate and control the motor.

Below is the sample code which I am posting again:

void SPI0_init(void){
MODRR0_SPI0RR = 1;
SPI0CR1_SPE =1;
SPI0CR1_SPIE = 1;
// SPI0CR1_MSTR = 1;
SPI0CR1_CPOL = 1;
SPI0CR1_CPHA = 1;
INT_CFADDR = 0x68;
INT_CFDATA0 = 4;
}

 

INTERRUPT void SPI0_ISR(void){
if(SPI0SR & SPI0SR_SPIF){
PTS_PTS3 = ~PTS_PTS3;
rx = SPI0DRL;
}
}

 

Below is the code which I am using to control the pmsm motor, here rx receive the data from SPI and control the motor:

void manualspeed1(void){
if(rx==65){
drvFOC.pospeControl.wRotElReq = 50;
}
else if(rx==86){
drvFOC.pospeControl.wRotElReq = -50;
}
}

0 项奖励
回复

4,390 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @ImranAviconn,

Can you scope all the SPI pins and post the waveforms here?

Have you selected correct CPOL, CPHA?

Maybe the issue is in the interrupt only, can you poll the SPIF flag?

 

BR, Daniel

0 项奖励
回复

4,380 次查看
ImranAviconn
Contributor II

@danielmartynek  I think the error is because of adding SPI0 in code warrior PMSM motor control source code.

Can I get any example code to run SPI0 in mc9s12zvml128 board for both master and slave.

 

标记 (1)
0 项奖励
回复

4,352 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @ImranAviconn,

There is an S12ZVL example (both master and slave, polling mode).

https://www.nxp.com/downloads/en/lab-test-software/DEVKIT-S12ZVL-LAB.zip

S12ZVL has the same SPI module as the S12ZVM.

I would recommend creating a new project and testing the SPI separately.

Once debugged, you can combine it with the motor control demo.

 

BR, Daniel

0 项奖励
回复

4,347 次查看
ImranAviconn
Contributor II

Hi, I have tried that code and found a strange problem that all the registers which I have set in the code are showing 0x00 value in the debugger. I have attached the source code and screenshot of debugger and this is happening for all register.

0 项奖励
回复

4,343 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Maybe there is an issue of the debugger.

Can you read the registers back in the code?

 

BR, Daniel

0 项奖励
回复

4,319 次查看
ImranAviconn
Contributor II

Hi, I have run the master in PMSM motor control source code on PORT S but when I set it as an slave it shows "No source available for "0xFFFFFF (0xFFFFFF)()" error on debugger when we click on resume in code warrior. On PORT T the MISO and MOSI remain in tri-state while clock and ss works well.

0 项奖励
回复

4,294 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @ImranAviconn,

Can you please test it seperately in a new project just for the SPI?

Which version of the board do you have?

 

BR, Daniel

 

 

 

0 项奖励
回复

4,273 次查看
ImranAviconn
Contributor II

Hi, @danielmartynek

i was able to configure the PORT S as the master in polling method and had the desired output signal on my oscilloscope, but when i try to use the interrupt method, somehow the rate of data becomes extremely high. i have attached the oscilloscope results in this message.

Blue signal is SS, Yellow is SCLK and Green is MOSI , the time(horizontal scale) is 500ns and as you can see the wave shape is not the desired wave shape. I have tried to set the baud rate divider to max but there is not difference in the output. Kindly see the spi0_init() configuration also :

void SPI0_init(void){
MODRR0_SPI0RR = 0; //1 = SPI port is on PORT-T | 0 = on port S
//SPI0CR1 = 0x5E; // for Master configuration
SPI0CR1 = 0xFE;// for Interrupt based master mode
//SPI0CR1 = 0x4E; // for Slave Configuration
SPI0CR2 = 0x10;
SPI0BR = 0x77;
}

标记 (1)
0 项奖励
回复

4,234 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @ImranAviconn,

I can't explain it. Maybe you can share the whole project so that we can test it on our side.

Please scope the BUS clock at the ECLK pin (NECLK = 0).

The baudrate is generated from the BUS clock by dividing it with the divider set in the SPIBR register.

You can compare the BUS CLK signal (ECLK) to the SCK signal of the SPI module.

Please read the SPIBR register back.

How the signal looks when you use the polling method?

 

BR, Daniel

 

 

 

 

 

0 项奖励
回复

4,027 次查看
ImranAviconn
Contributor II

Board  - MCSXSR1 CS12ZVM

Hi @danielmartynek

i was able to use port t for spi slave mode, currently i am using the interrupt mode for communication but as it is along with the PMSM motor drive example code . This interrupt is been served very after every 200ms which is very very slow, i have checked the master's output it has a time period of 25ms. So i think the priority of this interrupt is low.

SPI0CR1 = 0B11000000; // SPIE SPE SPTIE MSTR CPOL CPHA SSOE LSBFE
SPI0CR2 = 0B01000000; // x XFRW x MODFEN BIDIROE x SPISWAI SPC0

can you please help in setting the priority of SPI interrupt higher

the vector address is  1A0

dividing it by 4 gives 0x68

CFADDR = 0x60

but for the offset of 8 i dont know what to do exactly as CFDATA8 does not exists, kindly give some solution for this interrupt priority setting. as soon as you can

 

标记 (1)
0 项奖励
回复

3,998 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Helo @ImranAviconn,

I'm sorry for the delay, I'm out of office this week.

Regarding the priority, I believe it is well explained in this thread:

https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVC-interrupt-priority/m-p/617878

However, I can't say how the higher SPI interrupt priority will impact the motor control.

 

Regards,

Daniel

 

0 项奖励
回复

4,417 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @ImranAviconn,

I would recommend testing the ports in Master mode first.

There is no need to set the direction of the pins (DDRS) as this applies to the GPIO mode only.

The S12ZVM has the same SPI module (S12SPIV5) as the S12G.

Please find the example attached.

 

BR, Daniel

0 项奖励
回复

4,406 次查看
ImranAviconn
Contributor II

Hi @danielmartynek 

Thank you for your quick response I have tried that code in my file and its not working. I am editing in codewarrior PMSM source code so that I can communicate and control the motor.

Below is the sample code which I am posting again:

void SPI0_init(void){
MODRR0_SPI0RR = 1;
SPI0CR1_SPE =1;
SPI0CR1_SPIE = 1;
// SPI0CR1_MSTR = 1;
SPI0CR1_CPOL = 1;
SPI0CR1_CPHA = 1;
INT_CFADDR = 0x68;
INT_CFDATA0 = 4;
}

 

INTERRUPT void SPI0_ISR(void){
if(SPI0SR & SPI0SR_SPIF){
PTS_PTS3 = ~PTS_PTS3;
rx = SPI0DRL;
}
}

 

Below is the code which I am using to control the pmsm motor, here rx receive the data from SPI and control the motor:

void manualspeed1(void){
if(rx==65){
drvFOC.pospeControl.wRotElReq = 50;
}
else if(rx==86){
drvFOC.pospeControl.wRotElReq = -50;
}
}

0 项奖励
回复