9S12C128 SPI problem - SCK: not outputting a clock signal

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

9S12C128 SPI problem - SCK: not outputting a clock signal

1,931 Views
DavidN_
Contributor I

I am using CodeWarrior to program the C128 and the following code to initialize the SPI and make the MCU the master:

 

void DAC_Init(void)

{

    DDRM |= 0x38;  //PM5 = SPI clock out; PM4 = SPI master out

    PTM |= 0x08;    //PM3 = 1

    SPICR1 = 0x50; //Enable SPI and make master

    SPICR2 = 0x00; //Normal mode

    SPIBR = 0x07;   //93.75 kHz clock on PLL

}

 

I measured the SCK pin with an oscilloscope and got a flat line.  I tested the hardware and found that the SPI ports were working fine.  Do you guys think that there is something wrong with the code above or that the MCU could be fried?

 

 

Do you guys think this will work?:

 

I was thinking of changing the MCU to slave mode and then use the PWM to create a clock for the SCK pin as well as the device I was going to connect the SCK pin to.  So technically, the MCU and the device will both be in slave mode, just that the MCU will send out a signal over the MISO pin.  The device that I will be connecting to is a DAC. 

Labels (1)
0 Kudos
4 Replies

503 Views
bigmac
Specialist III

Hello,

 

You do not say which DAC you are using.  The SPI module should operate as a master since the DAC device will probably be a SPI slave. Two slave devices cannot communicate with each other.

 

The SPI polarity and phase parameters will need to be setup to suit the requirements of the DAC.  You will also need to allocate an additional GPIO pin for the purpose of providing the SS (or CS) output signal likely required by the DAC.

 

You also have not posted your code for the transfer of data between the MCU and the DAC.  Even if the DAC does not return any data, the flag clearing mechanisms within the SPI module must still be observed.

 

Regards,

Mac

 

0 Kudos

503 Views
DavidN_
Contributor I

I am using the DAC8581.  I specified PM3 to be a regular I/O pin for CS.

 

And here is the code for the transfer data:

 

#define SPIF 0x80

void DAC_out(unsigned short code)

{

  unsigned char dummy;

  PTM &= ~0x08;             // PM3=CS=0

  while((SPISR&0x20)==0);   // wait for SPTEF

  SPIDR = (code>>8);        // msbyte

  while((SPISR&SPIF)==0);   // gadfly wait

  dummy = SPIDR;            // clear SPIF

  while((SPISR&0x20)==0);   // wait for SPTEF

  SPIDR = code;             // lsbyte

  while((SPISR&SPIF)==0);   // gadfly wait

  dummy = SPIDR;            // clear SPIF

  PTM |= 0x08;              // PM3=CS=1

 

 

The main problem is that the PM5/SCK pin isn't giving me a clock signal.  I had the MCU tested to see if there were any problems with the SPI ports and none were found. 

0 Kudos

503 Views
bigmac
Specialist III

Hello,

 

Your code seems to be OK.  Although your clock rate is low, the clock pulses are sometimes difficult to catch on a non-storage oscilloscope, since only 16 pulses will be generated for each update.  I can't see any other reason why you would not observe the pulses.

 

I presume that the data pin of the DAC is connected to the MOSI pin.

 

Regards,

Mac

 

0 Kudos

503 Views
steph
Contributor I

i'm not good in english but i tried to be clear.

i have the same default and solution is to clear SPISR register before send data (in an "init function" for example).

i look this when i expect the spisr register with BDM, my program work fine,and not if i don't look for.

i presume because the BDM LINK read this register so it's like i clear this register.

all this because my new mcu is a new mask (ROHS)

stef

0 Kudos