HC12-µC & EVAL-AD5781 -> connection via SPI?

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

HC12-µC & EVAL-AD5781 -> connection via SPI?

1,034件の閲覧回数
CIA_MAN275
Contributor III

Hey!

 

I have connected the HC12 via SPI to the EVAL-AD5781. Here is my program for this connection:

 

 

 

#include <stdio.h>

#include <mc912d128.h>

main()
{
  DDRS = DDRS | 0xF0; /* outputs */
 
  PORTS = PORTS | 0x80; /* Bring SS high */
 
  SP0CR1 = 0x5A; /* 0b01011010 */
 
  SP0CR2 = 0; /* Normal mode */
 
  SP0BR = 0x00; /* 4 MHz SPI clock */
 
  PORTS = PORTS & ~0x80; /* Bring SS low to select slave */
 
  SP0DR = 0x200002;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  return SP0DR;
 
  SP0DR = 0x1003FC;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  return SP0DR;
 
  PORTS = PORTS | 0x80; /* Bring SS high to deselect slave */
 
  }

 

The Program above belongs to the following document:

 

http://www.ee.nmt.edu/~rison/ee308_spr02/supp/020320.pdf

 

And for those of you, who are good in german! Here the link for the other forum, where I discuss the problem.

 

http://www.mikrocontroller.net/topic/215922#2167148

 

Questions? Please ask!

 

Thx!

ラベル(1)
0 件の賞賛
返信
3 返答(返信)

722件の閲覧回数
CIA_MAN275
Contributor III

Newest Version of my program:

 

 

 

#include <stdio.h>

#include <mc912d128.h>

main()
{
 
  int i = 1;
 
  while (i>0)
  {
  unsigned char delete; /* was zum Datenauslesen und verwerfen */

  DDRS = DDRS | 0xF0; /* outputs */
      
  SP0CR1 = 0x5A; /* 0b01011010 */
 
  SP0CR2 = 0; /* Normal mode */
 
  SP0BR = 0x07; /* 31,25 kHz SPI clock */
     
  SP0DR = 0x20;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  delete = SP0DR; /* Daten auslesen und verwerfen */
 
  SP0DR = 0x00;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  delete = SP0DR; /* Daten auslesen und verwerfen */
 
  SP0DR = 0x02;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  delete = SP0DR; /* Daten auslesen und verwerfen */
 
  SP0DR = 0x10;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  delete = SP0DR; /* Daten auslesen und verwerfen */
 
  SP0DR = 0x03;
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
      
  delete = SP0DR; /* Daten auslesen und verwerfen */
      
  SP0DR = 0xFC;  
 
  while ((SP0SR & 0x80) == 0); /* wait for transfer to finish */
 
  delete = SP0DR; /* Daten auslesen und verwerfen */
  }

}

 

The while-loop is for debugging!

 

 

But it doesn't work :smileysad:

0 件の賞賛
返信

722件の閲覧回数
kef
Specialist I

To send first byte you need to read SPI status register first. In SPI status register SPTEF flag should be set. If this is the case, and only then you should write SPI data register.

 

P.S. Please decifier what bits (MSTR, CPOL etc) are set or cleared here:

SP0CR1 = 0x5A; /* 0b01011010 */

I don't remember which bit is where and can't help without spending extra time on finding 912DT datasheet and looking into it.

0 件の賞賛
返信

722件の閲覧回数
bigmac
Specialist III

Hello,

 

Further to Kef's comments, your code does not appear to be handling the /SYNC input signal to the DAC device.

 

Regards,

Mac

 

0 件の賞賛
返信