DSP 之I2C(Inter IC BUS)总线

DSP之 I2C(InterIC BUS)总线介绍: IIC总线介绍请看这:

IIC接口:

TMS320C550A包含IIC串口,可工作在100-400Kbps波特率之间,7位地址模式,该芯片包含主发送/接收和副发送/接收模式,可应用于DMA,中断,或者轮询事件。

IIC的时钟模式工作范围为7MHZ-12MHZ。

 

/*
 * Copyright (C) 2003 Texas Instruments Incorporated
 * All Rights Reserved
 */
 
 
#include <csl.h>
#include <csl_i2c.h>
#include <stdio.h>
#include "myiic.h"



//---------Global data definition---------
Uint16 mask = 1;    
Uint16 enable = 1;    
Uint16 databyte1[2]={0xA,0xB};  
int i=0,x;         
Uint16 datareceive[6] = { 0, 0, 0, 0, 0, 0 };
int y;

/* Declare and Initialize an I2C */
I2C_Init myInit = {
	0,					/* 7 bit address mode */
	0x0000,				/* own address */
	144,				/* clkout value (MHZ) */
	400,				/* a number between 10 and 400 */
	0,					/* 8 bits/byte to be received or transmitted */
	0,					/* DLB mode off */
	1					/* FREE mode on */
};


		


/* Declare and Initialize an I2C call Back Structure */
I2C_IsrAddr addr = {  
        myALIsr,
        myNACKIsr,
        myARDYIsr,
        myRRDYIsr,
        myXRDYIsr
};       

/* Declare and Initialize an I2C initialization structure */
I2C_Setup Init = {

        0,              /* 7 bit address mode */
        0x0020,         /* own address - don't care if master */
        144,            /* clkout value (Mhz)  */
        400,            /* a number between 10 and 400*/
        0,              /* number of bits/byte to be received or transmitted (8)*/
        0,              /* DLB mode on*/
        1               /* FREE mode of operation on*/

};

//---------Function prototypes---------

/* Reference start of interrupt vector table       */
/* This symbol is defined in the file, vectors.s55 */
extern void VECSTART(void);

#pragma CODE_SECTION (taskFunc, "tskSeg");
void taskFunc(void);



void UserMe(void)
{
	I2C_init(&myInit);
	
	y = I2C_read(datareceive, 		/* data buffer */
					6,				/* receives 6 of bytes of data */
					1,				/* in master receiver */
					0x50,			/* S-A-D..(n)	D-P mode */
					3,				/* to from the 0x50 address */
					30000,			/* with a timeout of 30000 */
					0);				/* and check for bus busy on */
					
	printf("I2C read: %d\n", y);
	
					
					
}


 
//---------main routine---------
void main(void)
{
    /* Initialize CSL library - This is REQUIRED !!! */
    CSL_init();
    
    /* Set IVPD/IVPH to start of interrupt vector table */
    /* 设置中断向量表 */
    IRQ_setVecs((Uint32)(&VECSTART)); 
    
    /* Call I2C example task/function */
    taskFunc();
}

void taskFunc(void) {

    /* Initialize the I2C using the iniitalization structure values */
    I2C_setup(&Init); 

    /* Set call back functions for I2C interrupt events
     * IIC structure used to assign functions for each interrupt structure
     * hook up the interrupt functions
     */
    I2C_setCallback(&addr);             
    
    /* Enable RRDY interrupt 
     * Data Receive Ready Interrupt
     */
    I2C_eventEnable(I2C_EVT_RRDY);  
 
    /* Enable all maskable interrupts */
    IRQ_globalEnable();                 // Enable interrupts
    
    /* Write a data byte to I2C */
    x=I2C_write(databyte1,			/* data buffer */
    				1,				/* send 1 bytes data */
    				1,				/* in master transmitter */
    				0x20,			/* to the 0x50 slave */
    				1,30000);		/* address with a timeout of 30000 */
    				
   
    if(!x) printf ("\nTEST PASSED\n");
    else printf ("\nTEST FAILED\n");
      
   /* Give some time for interrupt to occur */                                                                   
   for(i=0;i<10000;i++){ 
   };   
}    


 

#ifndef MYIIC_H_
#define MYIIC_H_


extern void myALIsr(void);  
extern void myNACKIsr(void); 
extern void myARDYIsr(void);
extern void myRRDYIsr(void);    
extern void myXRDYIsr(void);




#endif /*MYIIC_H_*/


 

/*
 * Copyright (C) 2003 Texas Instruments Incorporated
 * All Rights Reserved
 */
/*
 *---------myIsrs_i2c1.c---------
 * Function definitions for ISR/callBack functions
 */
 
 
#include <stdio.h>    

/* 将函数数据放在名为myisrSeg的代码段中 */
#pragma CODE_SECTION (myALIsr,"myisrSeg");
#pragma CODE_SECTION (myNACKIsr,"myisrSeg");
#pragma CODE_SECTION (myARDYIsr,"myisrSeg");
#pragma CODE_SECTION (myRRDYIsr,"myisrSeg");

void myALIsr()
{
   printf("I2C Arbitration Interrupt Occurred\n");
   // NOP 指令占一个字节,无实际意义
   asm("\tNOP                       ;====> I2C periodic interrupt routine");   
 
}   

void myNACKIsr()
{
   printf("I2C  NACK Interrupt Occurred\n");
   asm("\tNOP                       ;====> I2C periodic interrupt routine");   
 
}

void myARDYIsr()
{
   printf("I2C ARDY Interrupt Occurred\n");
   asm("\tNOP                       ;====> I2C periodic interrupt routine");   
 
}

void myRRDYIsr()
{
   printf("I2C RRDY Interrupt Occurred\n");
   asm("\tNOP                       ;====> I2C periodic interrupt routine");   
 
}

void myXRDYIsr()
{
   printf("I2C XRDY Interrupt Occurred\n");
   asm("\tNOP                       ;====> I2C periodic interrupt routine");   
 
}



 

欢迎各位浏览本博,相互交流共同提高-

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值