... and what about
https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVL-SCI-Driver/m-p/510065
sprintf can be added as an additonal function to prepare string from formated input values.
Best regards,
Ladislav
Hi,
CW does not support this function neither to ports not to console.
As an example, I have used a function sprintf for formated output and then used my UART function to send a text to the PC via serial channel. This was written for S12ZVC.
//==============================================================================
void SCI1_Init(UBYTE sci_num);
void SCI1_SendText(UBYTE sci_num, SBYTE *str);
//==============================================================================
typedef struct
{
UWORD SCIBD; /*00*//*01*/
UBYTE SCICR1; /*02*/
UBYTE SCICR2; /*03*/
UBYTE SCISR1; /*04*/
UBYTE SCISR2;
UBYTE SCIDRH;
UBYTE SCIDRL;
}tSCI_REGS;
//==============================================================================
// define base address of SCI regiters
UBYTE *sci_periph[] = { ( UBYTE * ) &SCI0BDH, ( UBYTE * ) &SCI1BDH };
//==============================================================================
/*******************************************************************************
Function Name : SCI_Init
Date : Sep-9-2014
Parameters : SCI channel
Modifies : NONE
Returns : NONE
Notes : SCI init at 9600bps @ 16MHz BUSCLK
TXD0 is on PJ1, RxD1 is on PJ0
Issues : NONE
*******************************************************************************/
void SCI_Init(UBYTE sci_num)
{
tSCI_REGS *sci;
sci = ( tSCI_REGS* ) ( sci_periph[sci_num] ); // get base addres of the SCI channel
// Calculation is valid for maskset N95G
// Old masksets must use formula BR = BUSCLK / (16*Baud rate)
//----- BR = BUSCLK / Baud rate = 16,000,000 / 9600 = 1667 = 0x683 -
//------------------------------------------------------
sci->SCIBD = 0x683; // prescaller value (depends on module clock frequency)
// prescaller = 0x683 9600Bd (16MHz bus clock is set)
//------------------------------------------------------
sci->SCICR1 = 0x44; // Loops sciswai rsrc m wake ilt pe pt
// 0-LOOPS=Rsrc=0 => 1 Single-wire mode with Rx input connected to TXD
// 1-SCI dis. in wait mode
// 0-if Rsrc=1-RxTx intern. connected if loops=1
// 0-start+8 data+1 stop bit
// 0-IDLE mark wake up
// 1-idle char. bit count begins after stop bit
// 0-parity fction disabled
// 0-odd parity
//------------------------------------------------------
sci->SCICR2 = 0x08; // tie tcie rie ilie te re rwu sbk
// 0-Tx empty intr disabled
// 0-Tx complete intr disabled
// 0-Rx full + OverRun interrupts
// 0-idle line intr disabled
// 1-transmitter enabled
// 0-receiver disabled
// 0-receiver normal operation
// 0-no break characters
//------------------------------------------------------
}
/*******************************************************************************
Function Name : SCI0_sendText
Date : Sep-9-2014
Parameters : SCI channel; pointer to a string to be sent
Modifies : NONE
Returns : NONE
Notes : send \0 terminated text out through SCI in polling mode
Issues : NONE
*******************************************************************************/
void SCI_SendText(UBYTE sci_num, SBYTE *str)
{
UBYTE i;
tSCI_REGS *sci;
sci = ( tSCI_REGS* ) ( sci_periph[sci_num] ); // get base addres of the SCI channel
i=0;
while(str[i]!='\0') // good to add a test for incorrect string..for example longer than x chars will be terminated
{
while(!(sci->SCISR1 & SCI0SR1_TC_MASK)){}; // write data to SCI (clear TC)
sci->SCIDRL = str[i];
i++;
}
}
//******************************************************************************
Of course this routine is written for more channels. It can be simplified.
.. and simple usage, without interrupt...
char txt[255];
( void ) sprintf( txt,"CAN0 rcvd: ST_ID= 0x%03LX data=", ( ULONG ) canRxMsg[0].id); // create text to send
SCI_SendText(0, txt ); // send txt via SCI 0
for(k=0; k<canRxMsg[0].len;k++)
{
( void ) sprintf( txt,"0x%02x,", canRxMsg[0].data[k]);
SCI_SendText(0, txt );
}
( void ) sprintf( txt, "\n\n\n\r" );
SCI_SendText(0, txt );
Best regards,
Ladislav
Hi
Add a few files, Looking forward to your reply.
A few more questions:
Q1:
typedef struct
{
UWORD SCIBD; /*00*//*01*/
UBYTE SCICR1; /*02*/
UBYTE SCICR2; /*03*/
UBYTE SCISR1; /*04*/
UBYTE SCISR2;
UBYTE SCIDRH;
UBYTE SCIDRL;
}tSCI_REGS;
These register names are different from my files, In addition, I have not clearly defined UWORD, UBYTE and SBYTE. Could you please give me a complete example of how to use it? Thank you very much
Hi
Thank you very much for your answer, I think it should be helpful.
Q1: Does CodeWarrior11.1 not support console output?
Q2: I am using MC9S12ZVLA128 of S12ZVL Family now. The code you gave applies to S12ZVC family. Does your example support S12ZVL family?
Q3: I used the latest io_map.h file, which is a little different from the field definition in the code you gave, could you please help me make adjustments?