This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6713 I2C Initialization in assembly

Hello there!

I'm trying to initialize i2c in master-transmitter mode and send data with c6713 using Code Composer Studio and assembly, but can't seem to get it to work. The problem is that there's no signal on SDA and SCL pins after I start the program.

Here's a initialization part:of my code:

; Place I2C in reset state (IRS = 0 in ICMDR)
	MVKL .S1 0x0024,A1
	MVKLH .S1 0x01B4,A1
	MVKL .S1 0x0,A2
	STW A2,*A1
	NOP 5
; Initialization procedure - I2CMDR
	MVKL .S1 0x0024,A1
	MVKLH .S1 0x01B4,A1
	MVKL .S1 0x690,A2
	STW A2,*A1
	NOP 5
; Configure the slave address
	MVKL .S1 0x001C,A3
	MVKLH .S1 0x01B4,A3
	MVKL .S1 0x0,A4
	STW A4,*A3
	NOP 5
; Set up I2C prescaled module clock - I2CPSC
	MVKL .S1 0x0030,A5
	MVKLH .S1 0x01B4,A5
	MVKL .S1 0x0,A6
	STW A6,*A5
	NOP 5
; Program clock control registers - I2CCLKL and I2CCLKH
	MVKL .S1 0x000C,A7
	MVKLH .S1 0x01B4,A7
	MVKL .S1 0x12,A8
	STW A8,*A7
	NOP 5
	MVKL .S1 0x0010,A9
	MVKLH .S1 0x01B4,A9
	MVKL .S1 0x12,A10
	STW A10,*A9
	NOP 5
; Configure the master address
	MVKL .S1 0x0000,A1
	MVKLH .S1 0x01B4,A1
	MVKL .S1 0x0,A2
	STW A2,*A1
	NOP 5
; Configure data transmit register - I2CDXR
	MVKL .S1 0x0020,A5
	MVKLH .S1 0x01B4,A5
	MVKL .S1 0x1F,A6
	STW A6,*A5
	NOP 5
; Take I2C controller out of reset
	MVKL .S1 0x0024,A7
	MVKLH .S1 0x01B4,A7
	MVKL .S1 0x6A0,A8
	STW A8,*A7
	NOP 5
; Generate a START event
	MVKL .S1 0x0024,A9
	MVKLH .S1 0x01B4,A9
	MVKL .S1 0x26A0,A10
	STW A10,*A9
	NOP 5

Thanks in advance!

  • Nick,

    Welcome to the TI E2E forum. I hope you will find many good answers here and in the TI.com documents and in the TI Wiki Pages. Be sure to search those for helpful information and to browse for the questions others may have asked on similar topics.

    Why would you want to write this in assembly? Surely we have C code examples for using the I2C port, in CSL or in the DSK's BSL. You need to find working examples and at least start with those. When we put out examples, they have been tested and had a lot of work put into them to make sure they will work.

    It is too difficult to debug someone's assembly code, or even C code that is written custom. On what did you base your assignments?

    Regards,
    RandyP

  • Hello RandyP!

    Unfortunately it is a part of my project's specification and it requires for i2c initialization to be written in assembly.

    The first thing I did after reading TMS320C6713 datasheet and TMS320C6000 DSP I2C reference guide, was to look for C solutions and try to see how it works in practice.

    The code above is the one I came up with afterwards. It should continuously send "0x1F" through the SDA, to all the slaves.

    Some additional information that might help: SYSCLK2 is 12.5 MHz; I2CPSC, I2CCLKL and I2CCLKH are configured to produce the master clock frequency of 250 KHz.

    Thank you very much for your help!

  • The situation has been resolved, I figured it out myself.

    Thank you for your time anyway!

  • Nick,

    Good job finding your problem.

    If you would like to support the E2E community, it will help future readers to know what the problem was. Your work will then be available for a long time helping others like yourself. Similarly, you will be able to find answers to many of your future questions here because of good debuggers like yourself.

    Regards,
    RandyP

  • Well, I didn't know that you have to poll BB bit in I2CSTR before generating START event. Adding that simple thing fixed my problem.

    Hope that will help somebody like me, who can not read documentation properly :)

  • Nick,

    Thanks for posting that. I have marked it as the Answer to make it easier for people to find in the future.

    May I ask, why do you use the NOP 5 after every STW instruction? Did the User Guide suggest a delay between the registers being written?

    Also, are you aware of the register-relative addressing mode (see the CPU & Instruction Set Reference Guide for more information)? You could set an addressing register to the base address of the I2C registers 0x01b40000 and then use register-relative addressing to write all the rest of the registers in the I2C register space.

    I have learned these things by writing in C, keeping the assembly output, and studying that assembly output for good ideas.

    Regards,
    RandyP

  • Well, I'm relatively new to assembly and I've read in "TMS320C6000 CPU and Instruction Set Reference Guide", that it takes 5 cycles for STW to write data to memory. And, I wanted to make sure that everything works properly.

    I've read about register-relative addressing mode, just haven't implemented it into my project yet.

    I was also thinking about using software pipelining, as I've never done it in assembly.