I am writing a DAC driver for the Freedom KL25z and it does not work. I am testing it with an oscilloscope, but there is no rise in voltage.
My configuration function is using the only DAC channel available for the KL25...
Connected oscilloscope voltage to PORTE30 pin and oscilloscope ground to KL25 GND pin.
UPDATE, forgot to write filenames and actual question
Here is my DACDriver.c file
#include "DACDriver.h"
unsigned char bflgSendingData = 0;
unsigned short* wpSetPattern;
unsigned short wSetPatternSize;
void vfnDACInit()
{
SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK;
DAC0_C0 |= DAC_C0_DACRFS_MASK;
PORTE_PCR30 = PORT_PCR_MUX(0);
DAC0_DAT0L = 0x00;
DAC0_DAT0H |= 0x0;
DAC0_DAT1L = 0xFF;
DAC0_DAT1H |= 0xF;
DAC0_C0 |= DAC_C0_DACEN_MASK;
}
void vfnDACSetValue(unsigned short wValue)
{
DAC0_DAT0L = (unsigned char)(wValue & 0xFF);
DAC0_DAT0H = (unsigned char)(wValue >> 8);
}
unsigned char bfnDACDriver(void)
{
vfnDACSetValue(0xFF);
/*This is just a test; in my main, I'm just trying to see an output here.
But the main logic should be like the code below*/
/*if(bflgSendingData){
if(wSetPatternSize){
vfnDACSetValue(wpSetPattern);
wpSetPattern++;
wSetPatternSize--;
}
return 1;
}else{
return 0;
}
*/
}
unsigned char bfnDACSetPattern(unsigned short* wpPattern, unsigned short wPatternSize)
{
if(0 == bflgSendingData){
wpSetPattern = wpPattern;
wSetPatternSize = wPatternSize;
bflgSendingData = 1;
return 1;
}else{
return 0;
}
}
UPDATE, forgot to include this file
Here is my DACDriver.h file
#ifndef __DACDRIVER_H_
#define __DACDRIVER_H_
#include "derivative.h"
void vfnDACInit(void);
unsigned char bfnDACDriver(void);
unsigned char bfnDACSetPattern(unsigned short* wpPattern, unsigned short wPatternSize);
#endif /* __DACDRIVER_H_ */
Here is my main.c file, which right now only has a little test so I can see some output
#include "DACDriver.h"
int main(void)
{
unsigned char pattern[] = {
0xFF, 0xEF, 0xDF, 0xCF, 0xBF, 0xAF,
0x9F, 0x8F, 0x7F, 0x6F, 0x5F, 0x4F, 0x3F, 0x2F, 0x1F,
0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A,
0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
vfnDACInit();
for(;;) {
bfnDACDriver();
}
return 0;
}
I am trying to be the most autodidact possible, but I have run out of ideas...
My main questions are: Do you see any error here? How do I make it work? Am I missing something?
Thanks a lot!!