hi,all
We have to use the SPI to transfer datas. and i try to using the following
s-function to transfer the data through the slaveDSP.
But I can't get any ouput and even the SCLK is keeping high.
/*******************************************************************************
FILE: onetran.c
DESCRIPTION:
S-function to transmit one data through the spi mode to extra device with
the
slave application (DS1103 version).
Copyright (c) 1997-2005 dSPACE GmbH, GERMANY
*******************************************************************************/
#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME onetran
#include "simstruc.h"
/* Include basic real-time environment header. */
/* Include the slave application source code to be found in
%DSPACE_ROOT%\ds1103\Slvdsp1103.h */
#ifndef MATLAB_MEX_FILE
#include <brtenv.h>
#include <F:\dspace\ds1103\ds1103.h>
#include <F:\dspace\ds1103\Slvdsp1103.h>
#endif
/* Function: mdlInitializeSizes =========================== */
static void mdlInitializeSizes(SimStruct *S)
{
/* This S-function has no parameters. */
ssSetNumSFcnParams(S, 0); /* No. of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return;
/* Set the number of states to zero. */
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
/* We have 4 input port with width 1*/
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortDataType(S, 0, SS_INT16);
ssSetInputPortDirectFeedThrough(S, 0, 1);
/* We have no output ports.*/
if (!ssSetNumOutputPorts(S, 0)) return;
/* This S-function has one sample time. */
ssSetNumSampleTimes(S, 1);
/* No work vectors and other special features are used. */
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
/* No additional options are used. */
ssSetOptions(S, 0);
}
/* Function: mdlInitializeSampleTimes ===================== */
static void mdlInitializeSampleTimes(SimStruct *S)
{
/* Use INHERITED_sample time and no offset. */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS
#if defined(MDL_INITIALIZE_CONDITIONS)
/* Function: mdlInitializeConditions =================================== */
static void mdlInitializeConditions(SimStruct *S)
{
#ifndef MATLAB_MEX_FILE
{
ds1103_slave_dsp_communication_init();
ds1103_slave_dsp_spi_init(0, SLVDSP1103_SPI_MASTER, 115200,
SLVDSP1103_SPI_CLKPOL_FALL, SLVDSP1103_SPI_CLKPHS_WOD, 8);
}
#endif
}
#endif
#undef MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)
/* Function: mdlStart =================================== */
static void mdlStart(SimStruct *S)
{
}
#endif /* MDL_START */
/* Function: mdlOutputs ==================================*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
InputRealPtrsType u0 = ssGetInputPortRealSignalPtrs(S,0);
#ifndef MATLAB_MEX_FILE
int16_T idx0 = DSCOMDEF_AUTO_INDEX;
ds1103_slave_dsp_spi_write_register(0, &idx0);
ds1103_slave_dsp_spi_write(0,idx0, *u0[0]);
#endif
}
#undef MDL_UPDATE /* Change to #undef to remove function */
#if defined(MDL_UPDATE)
/* Function: mdlUpdate
======================================================
* Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is
useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S, int_T tid)
{
}
#endif /* MDL_UPDATE */
/* Function: mdlTerminate ==================================*/
static void mdlTerminate(SimStruct *S)
{
}
#ifdef MATLAB_MEX_FILE /* Compile as a MEX file? */
#include "simulink.c" /* MEX file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration fcn */
#endif
Can you tell me what is wrong?
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
DSpace-tech mailing list
DSpace-tech@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspace-tech