Int16 sinetable[48] = { 0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b, 0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x763f, 0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4, 0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75, 0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1, 0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c }; Int16 msec, sec; Int16 sample; MCASP1_GBLCTL = 0; MCASP1_RGBLCTL = 0; MCASP1_XGBLCTL = 0; MCASP1_PWRDEMU = 1; MCASP1_RMASK = 0xffffffff; MCASP1_RFMT = 0x00008078; // MSB 16bit, 0-delay, no pad, CFGBus MCASP1_AFSRCTL = 0x00000112; // 2TDM, 1bit Rising edge INTERNAL FS, word MCASP1_ACLKRCTL = 0x000000AF; // Rising INTERNAL CLK(from tx side) MCASP1_AHCLKRCTL = 0x00000000; // INT CLK (from tx side) MCASP1_RTDM = 0x00000003; // Slots 0,1 MCASP1_RINTCTL = 0x00000000; // Not used MCASP1_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-256 MCASP1_XMASK = 0xffffffff; // No padding used MCASP1_XFMT = 0x00008078; // MSB 16bit, 0-delay, no pad, CFGBus MCASP1_AFSXCTL = 0x00000112; // 2TDM, 1bit Rising edge INTERNAL FS, word MCASP1_ACLKXCTL = 0x000000AF; // ASYNC, Rising INTERNAL CLK, div-by-16 MCASP1_AHCLKXCTL = 0x00000000; // INT CLK, div-by-4 MCASP1_XTDM = 0x00000003; // Slots 0,1 MCASP1_XINTCTL = 0x00000000; // Not used MCASP1_XCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-256 MCASP1_SRCTL5 = 0x000E; // MCASP1.AXR1[5] <-- DOUT MCASP1_SRCTL0 = 0x000D; // MCASP1.AXR1[0] --> DIN MCASP1_PFUNC = 0x00; MCASP1_PDIR = 0x14000001; // ACLKX1, AFSX1 and AXR1[0] MCASP1_DITCTL = 0x00000000; // Not used MCASP1_DLBCTL = 0x00000000; // Not used MCASP1_AMUTE = 0x00000000; // Not used /* Starting sections of the McASP*/ MCASP1_XGBLCTL |= GBLCTL_XHCLKRST_ON; // HS Clk while ( ( MCASP1_XGBLCTL & GBLCTL_XHCLKRST_ON ) != GBLCTL_XHCLKRST_ON ); MCASP1_RGBLCTL |= GBLCTL_RHCLKRST_ON; // HS Clk while ( ( MCASP1_RGBLCTL & GBLCTL_RHCLKRST_ON ) != GBLCTL_RHCLKRST_ON ); MCASP1_XGBLCTL |= GBLCTL_XCLKRST_ON; // Clk while ( ( MCASP1_XGBLCTL & GBLCTL_XCLKRST_ON ) != GBLCTL_XCLKRST_ON ); MCASP1_RGBLCTL |= GBLCTL_RCLKRST_ON; // Clk while ( ( MCASP1_RGBLCTL & GBLCTL_RCLKRST_ON ) != GBLCTL_RCLKRST_ON ); /*MCASP1_RINTCTL |= RDATA; // enable McASP XMT/RCV interrupts while ( ( MCASP1_RINTCTL & RDATA ) != RDATA ); // see #defines at top of file MCASP1_XINTCTL |= XDATA; while ( ( MCASP1_XINTCTL & XDATA ) != XDATA ); // see #defines at top of file*/ MCASP1_XSTAT = 0x0000ffff; // Clear all MCASP1_RSTAT = 0x0000ffff; // Clear all MCASP1_XGBLCTL |= GBLCTL_XSRCLR_ON; // Serialize while ( ( MCASP1_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON ); MCASP1_RGBLCTL |= GBLCTL_RSRCLR_ON; // Serialize while ( ( MCASP1_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON ); /* Write a 0, so that no underrun occurs after releasing the state machine */ MCASP1_XBUF0 = 0; MCASP1_XGBLCTL |= GBLCTL_XSMRST_ON; // State Machine while ( ( MCASP1_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON ); MCASP1_RGBLCTL |= GBLCTL_RSMRST_ON; // State Machine while ( ( MCASP1_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON ); MCASP1_XGBLCTL |= GBLCTL_XFRST_ON; // Frame Sync while ( ( MCASP1_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON ); MCASP1_RGBLCTL |= GBLCTL_RFRST_ON; // Frame Sync while ( ( MCASP1_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON ); /* Start by sending a dummy write */ while( ! ( MCASP1_SRCTL0 & 0x10 ) ); // Check for Tx ready MCASP1_XBUF0 = 0; /* Play Tone */ for ( sec = 0 ; sec < 1000000 ; sec++ ) { for ( msec = 0 ; msec < 1000 ; msec++ ) { for ( sample = 0 ; sample < 48 ; sample++ ) { /* Send a sample to the left channel */ while ( ! ( MCASP1_SRCTL0 & 0x10 ) ); MCASP1_XBUF0_32BIT = (sinetable[sample] << 15) | 0x00000000; /* Send a sample to the right channel */ while ( ! ( MCASP1_SRCTL0 & 0x10 ) ); MCASP1_XBUF0_32BIT = (sinetable[sample] << 15) | 0x00000000; } } } /* Close McASP */ MCASP1_SRCTL0 = 0; // Serializers MCASP1_SRCTL1 = 0; MCASP1_SRCTL2 = 0; MCASP1_SRCTL3 = 0; MCASP1_SRCTL5 = 0; MCASP1_GBLCTL = 0; // Global Reset }