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.

I2C Busy Flag

Other Parts Discussed in Thread: TM4C123GH6PM

Hello,

I am working on my own board. It is my first board which i made. I have a problem with I2C, when i try to send any byte, controller goes to busy state and never get out from busy state. I don't know why problem is, maybe caused of board and connection with sensors or software. So i wanna make sure that problem is about software or not.

Firstly, i am making clock configuration. I used 8Mhz crystal, my microcontroller is TM4C123GH6PM. System Clock is set 80Mhz

I am using PA6 and PA7.

Port PIN Configuration code is

GPIOA->DIR |= (1UL << 6);//I don't know it is necessary or not 
GPIOA->AFSEL |= (1UL << 6) & (1UL << 7); // 6. and 7. pin configured as alternative mode
GPIOA->PCTL = 0x33000009UL; // 6. pin SCL 7.pin SDA, the others pins stay default
GPIOA->ODR |= 0x00000080UL; // PORTA 7. pin opendrain 
GPIOA->DEN |= (1UL<<6) & (1UL<<7); // Port 6 and 7 is digital pin

I2C Configuration

I2C1->MCR = (1UL << 4); // Master Mode Enable
I2C1->MTPR |= 0x09; // 80 Mhz Clock, 400kbps communication

Transmit One Byte Code

while(!(I2C1->MCS & (1UL << 5)));

I2C1->MSA = (slave_adress << 1); 
I2C1->MDR = reg_adress; 

while(I2C1->MCS & (1UL << 6)); 

I2C1->MCS = 0x0000000F;


while(I2C1->MCS & (1UL << 0));  // System stay here forever

and i saw that when i wrote on MDR register, i just see 0x00 insife of this register on debug mode.

Thanks

  • Hi,

         Welcome, since it is your first post in the forum.

         Most people here are accustomed to using Tivaware C API's for their development, instead of direct register read/write. So, I would advice you to look into the existing I2C example code snippets that uses Tivaware C API's. You, can find those at \\examples\peripherals\i2c. You, can use the Tivaware Peripheral Driver Library User Guide doc and \\driverlib\i2c.c as guide for reviewing the I2C example codes.

    -kel

  • Hello Bilici,

    Can you check the values of GPIO PortA AFSEL and DEN? I don't think these two C lines are doing what you want them to:

    GPIOA->AFSEL |= (1UL << 6) & (1UL << 7);

    GPIOA->DEN |= (1UL<<6) & (1UL<<7);

  • Please accept this as Vote #2 - "Do not use Direct Register Read/Writes" @ this early stage.

    It is hugely unfortunate that MCU Manual illustrates often w/such Register use.  (major mistake - imho)

    As poster/friend Kel stated - many "C Code" examples exist - you will likely do better to spend next few days navigating this vast web-site & learning how/where critical & helpful code examples appear. 

    Suggest that you find latest SW-DRL-UGxxxx which systematically lists literally hundreds of pre-written/tested functions - sure to speed, ease & enhance your learning.

    And - even though MCU "claims" to have pull-up resistors on I2C pair - so much safer to install 4K7 - 10K external Rs - and know they are there & proper.  Further suggest that you begin your debug w/basic gpio test/verify - not w/the far more complex I2C.  (we know that's your desire - but you need a foundation to best appreciate the demands of the more advanced MCU peripherals - and mastering the easier rather than harder (i.e. KISS) - warrants your consideration...)

  • Hello Mitch, 

    thanks for answer, i dont know why i used directly &, just on  these 2 lines i used &.