<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: C language code for SCI for 68HC908AP64 (DEMO908AP64 board) in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/C-language-code-for-SCI-for-68HC908AP64-DEMO908AP64-board/m-p/130103#M2308</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;After spending more time reading mcu datasheet, I could write following C code to send some strings to computer via serial port.&lt;BR /&gt;I used 9.8304Mhz crystal though.&lt;BR /&gt;There was some statement on the demo board manual that this crystal is for debug and I&lt;BR /&gt;took that too literaly :smileyhappy: I will try with 32.xxxx KHz crystal also.&lt;BR /&gt;&lt;BR /&gt;there are way too many clock frequency calculations :smileysad:&lt;BR /&gt;&lt;BR /&gt;-------------&lt;BR /&gt;&lt;BR /&gt;void usart_init(void) {&lt;BR /&gt;&lt;BR /&gt; CONFIG2 = 0x01; /* Internal data bus clock source used as clock source for SCI */&lt;BR /&gt; &lt;BR /&gt;// 2. Configure the microcontroller’s pins for SCI communications&lt;BR /&gt;// PTB[2] as TxD, PTB[3]RxD [x,x,x,x,RxD,TxD,x,x]&lt;BR /&gt; DDRB &amp;amp;= ~(0x08); /* Configure Rx pin as input for reception */&lt;BR /&gt; PTB |= 0x04; /* Set Tx pin to have an idle state */&lt;BR /&gt; DDRB |= 0x04; /* Configure Tx pin as output for transmission */&lt;BR /&gt; &lt;BR /&gt;// 3. Configure SCI control register 1, 2, and 3&lt;BR /&gt; SCC1 = 0x00; /* Loop mode disabled, disable SCI, Tx output not inverted,&lt;BR /&gt; 8-bit characters, idle line wakeup, disable parity bit */&lt;BR /&gt; &lt;BR /&gt; //SCC2 = 0x20; /* SCRIE SCI Receive Intr Enable, Disable transmitter and receiver */&lt;BR /&gt; SCC2 = 0x00; // disable receive intr &lt;BR /&gt; SCC3 = 0x00; /* Disable all error interrupts */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// SCI Baud Rate Register SCBR[x,x,SCP1,SCP0,x,SCR2,SCR1,SCR0] &lt;BR /&gt;//&lt;BR /&gt;// PCTL[BCS] ; 0 = CGMXCLK divided by two drives CGMOUT [default after reset]&lt;BR /&gt;// 1 = CGMPCLK divided by two drives CGMOUT&lt;BR /&gt;// SIM Bus Clock = CGMOUT/2&lt;BR /&gt;// when BCS == 0; CGMOUT = CGMXCLK/2&lt;BR /&gt;// ==&amp;gt; fBus = Bus clock = CGMXCLK/4 [default after reset]&lt;BR /&gt;// ==&amp;gt; fBus = XTAL/4&lt;BR /&gt;&lt;BR /&gt;// If selecting external crystal of *** 9.8304 MHz ***&lt;BR /&gt;// SCP1,SCP0 = 0,0 =&amp;gt; PD = 1 ; SCR2,SCR1,SCR0 = 0,1,0; BD = 4&lt;BR /&gt;// SCBR = [0 0 SCP1 SCP0 R SCR2 SCR1 SCR0] = 00000010 = 0x02&lt;BR /&gt;//&lt;BR /&gt;// SCI clock source&lt;BR /&gt;// baud rate = ---------------- &lt;BR /&gt;// 64 × PD × BD&lt;BR /&gt;//&lt;BR /&gt;// SCI clock source = fBUS or CGMXCLK&lt;BR /&gt;// (selected by SCIBDSRC bit in CONFIG2 register) &lt;BR /&gt;// CONFIG2[SCIBDSRC],bit0 = 0 default after reset, &lt;BR /&gt;// 1 = Internal data bus clock, fBUS, is used as clock source for SCI&lt;BR /&gt;// 0 = Oscillator clock, CGMXCLK, is used as clock source for SCI&lt;BR /&gt;&lt;BR /&gt;// .To use fBUS as clock source&lt;BR /&gt;// CONFIG2 = 0x01&lt;BR /&gt;// baud rate = fBUS/(64 * PD * BD)&lt;BR /&gt;// = (XTAL/4) / ( 64 * 1 * 4)&lt;BR /&gt;// = (9.8304/4) / ( 64 * 1 * 4)&lt;BR /&gt;// = 9600&lt;BR /&gt; SCBR = 0x02;&lt;BR /&gt;&lt;BR /&gt;// 5. Enable receiver, transmitter, and SCI module&lt;BR /&gt; SCC1 |= 0x40; /* Enable SCI Module */&lt;BR /&gt; SCC2 |= 0x0C; /* Enable Transmitter and Receiver */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void usart_write_char(char c) {&lt;BR /&gt; while ((SCS1 &amp;amp; 0x80) == 0); /* Wait for the transmitter to be empty */&lt;BR /&gt; SCDR = c; // write data to data register&lt;BR /&gt; delay(1); &lt;BR /&gt;}&lt;BR /&gt;------------&lt;BR /&gt;- Surinder&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Sep 2006 18:29:30 GMT</pubDate>
    <dc:creator>surinder</dc:creator>
    <dc:date>2006-09-14T18:29:30Z</dc:date>
    <item>
      <title>C language code for SCI for 68HC908AP64 (DEMO908AP64 board)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/C-language-code-for-SCI-for-68HC908AP64-DEMO908AP64-board/m-p/130102#M2307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to write C program using SCI on DEMO908AP64.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not able to understand configuratin for calculating baud rate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I read 68HC908AP64 datasheet and AN3035 (Using the HC08 SCI Module).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I read assembly code supplied with demo board.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am more confused.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is option of two xtal on the board.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I chose 32.768KHz&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are three clock sources for Oscillator module MUX.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) external crystal(XCLK) 2) external RC (RCCLK) 3) internal clock (ICLK)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What is default value of ICLK?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Which one is selected by default? more specifically between ICLK and others.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reference output of the OSC Module "CGMRCLK", goes through PLL and freq is multiplied K number of times.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What is the PLL frequency multiplier value by default ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In CGM, there is option of selecting between these two.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CGMXCLK (coming directly from OSC module) OR CGMPCLK (multipled freq out from PLL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Either of these divided by 2 to get CGMOUT.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What is the default selection?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And, Bus clock = CGMOUT ÷ 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it true that Bus Clock will be always (CGMXCLK or CGMPCLK)/4. Any exceptions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is CGMXCLK frequency equal to XCLK in case external crystal is selected by OSC Module?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now the baud selection part &lt;/SPAN&gt;&lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif"&gt;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From application note AN3035&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Configure the SCI clock source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;CONFIG2 = 0x01; /* Internal data bus clock source used as clock source for SCI */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;/*****************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;* Fbus = XTAL/4 2.4576 MHz *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;* Baud Rate = -------------------- = ---------- = 9600 bps *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;* 64 x SCP1:0 x SCR2:0 64 x 1 x 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SCBR = 0x02; *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is meant by internal data bus clock? ICLK or Bus clock?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess it is Bus clock. In the scenario taken by this application note,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it appears that external crystal of 9.8304 MHz is used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want 9600 bps baud, 8 bit data, no parity, 1 stop bit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I need C code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To use 32.768KHz external crystal, PLL is required to increase the frequency so that it can be divided &lt;/SPAN&gt;&lt;SPAN aria-label="Happy" class="emoticon_happy emoticon-inline" style="height:16px;width:16px;"&gt;&lt;/SPAN&gt;&lt;SPAN&gt; (by atleast 64 * 4) to get 9600 with some accuracy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any program somewhere or someone can suggest the relevant configuration&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;register values?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, How can I get Bus clock frequency programmaticaly in C?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Surinder&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Sep 2006 21:17:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/C-language-code-for-SCI-for-68HC908AP64-DEMO908AP64-board/m-p/130102#M2307</guid>
      <dc:creator>surinder</dc:creator>
      <dc:date>2006-09-13T21:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: C language code for SCI for 68HC908AP64 (DEMO908AP64 board)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/C-language-code-for-SCI-for-68HC908AP64-DEMO908AP64-board/m-p/130103#M2308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;After spending more time reading mcu datasheet, I could write following C code to send some strings to computer via serial port.&lt;BR /&gt;I used 9.8304Mhz crystal though.&lt;BR /&gt;There was some statement on the demo board manual that this crystal is for debug and I&lt;BR /&gt;took that too literaly :smileyhappy: I will try with 32.xxxx KHz crystal also.&lt;BR /&gt;&lt;BR /&gt;there are way too many clock frequency calculations :smileysad:&lt;BR /&gt;&lt;BR /&gt;-------------&lt;BR /&gt;&lt;BR /&gt;void usart_init(void) {&lt;BR /&gt;&lt;BR /&gt; CONFIG2 = 0x01; /* Internal data bus clock source used as clock source for SCI */&lt;BR /&gt; &lt;BR /&gt;// 2. Configure the microcontroller’s pins for SCI communications&lt;BR /&gt;// PTB[2] as TxD, PTB[3]RxD [x,x,x,x,RxD,TxD,x,x]&lt;BR /&gt; DDRB &amp;amp;= ~(0x08); /* Configure Rx pin as input for reception */&lt;BR /&gt; PTB |= 0x04; /* Set Tx pin to have an idle state */&lt;BR /&gt; DDRB |= 0x04; /* Configure Tx pin as output for transmission */&lt;BR /&gt; &lt;BR /&gt;// 3. Configure SCI control register 1, 2, and 3&lt;BR /&gt; SCC1 = 0x00; /* Loop mode disabled, disable SCI, Tx output not inverted,&lt;BR /&gt; 8-bit characters, idle line wakeup, disable parity bit */&lt;BR /&gt; &lt;BR /&gt; //SCC2 = 0x20; /* SCRIE SCI Receive Intr Enable, Disable transmitter and receiver */&lt;BR /&gt; SCC2 = 0x00; // disable receive intr &lt;BR /&gt; SCC3 = 0x00; /* Disable all error interrupts */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// SCI Baud Rate Register SCBR[x,x,SCP1,SCP0,x,SCR2,SCR1,SCR0] &lt;BR /&gt;//&lt;BR /&gt;// PCTL[BCS] ; 0 = CGMXCLK divided by two drives CGMOUT [default after reset]&lt;BR /&gt;// 1 = CGMPCLK divided by two drives CGMOUT&lt;BR /&gt;// SIM Bus Clock = CGMOUT/2&lt;BR /&gt;// when BCS == 0; CGMOUT = CGMXCLK/2&lt;BR /&gt;// ==&amp;gt; fBus = Bus clock = CGMXCLK/4 [default after reset]&lt;BR /&gt;// ==&amp;gt; fBus = XTAL/4&lt;BR /&gt;&lt;BR /&gt;// If selecting external crystal of *** 9.8304 MHz ***&lt;BR /&gt;// SCP1,SCP0 = 0,0 =&amp;gt; PD = 1 ; SCR2,SCR1,SCR0 = 0,1,0; BD = 4&lt;BR /&gt;// SCBR = [0 0 SCP1 SCP0 R SCR2 SCR1 SCR0] = 00000010 = 0x02&lt;BR /&gt;//&lt;BR /&gt;// SCI clock source&lt;BR /&gt;// baud rate = ---------------- &lt;BR /&gt;// 64 × PD × BD&lt;BR /&gt;//&lt;BR /&gt;// SCI clock source = fBUS or CGMXCLK&lt;BR /&gt;// (selected by SCIBDSRC bit in CONFIG2 register) &lt;BR /&gt;// CONFIG2[SCIBDSRC],bit0 = 0 default after reset, &lt;BR /&gt;// 1 = Internal data bus clock, fBUS, is used as clock source for SCI&lt;BR /&gt;// 0 = Oscillator clock, CGMXCLK, is used as clock source for SCI&lt;BR /&gt;&lt;BR /&gt;// .To use fBUS as clock source&lt;BR /&gt;// CONFIG2 = 0x01&lt;BR /&gt;// baud rate = fBUS/(64 * PD * BD)&lt;BR /&gt;// = (XTAL/4) / ( 64 * 1 * 4)&lt;BR /&gt;// = (9.8304/4) / ( 64 * 1 * 4)&lt;BR /&gt;// = 9600&lt;BR /&gt; SCBR = 0x02;&lt;BR /&gt;&lt;BR /&gt;// 5. Enable receiver, transmitter, and SCI module&lt;BR /&gt; SCC1 |= 0x40; /* Enable SCI Module */&lt;BR /&gt; SCC2 |= 0x0C; /* Enable Transmitter and Receiver */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;void usart_write_char(char c) {&lt;BR /&gt; while ((SCS1 &amp;amp; 0x80) == 0); /* Wait for the transmitter to be empty */&lt;BR /&gt; SCDR = c; // write data to data register&lt;BR /&gt; delay(1); &lt;BR /&gt;}&lt;BR /&gt;------------&lt;BR /&gt;- Surinder&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Sep 2006 18:29:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/C-language-code-for-SCI-for-68HC908AP64-DEMO908AP64-board/m-p/130103#M2308</guid>
      <dc:creator>surinder</dc:creator>
      <dc:date>2006-09-14T18:29:30Z</dc:date>
    </item>
  </channel>
</rss>

