Freertos_twi_master not work for me

I have an Arduino Due board + mcp4728 I2C DAC board. I can do the following from Arduino IDE with Wire Library.

error = Wire.endTransmission();

I want to do the something using free freertos_twi_master and atmel studio 7

const freertos_peripheral_options_t freertos_driver_parameters = {
	.interrupt_priority = 0x0f,
	.operation_mode = TWI_I2C_MASTER,
	.receive_buffer = NULL,
	.receive_buffer_size = 0
uint8_t buffer[3];
buffer[0] = 0x2C;
buffer[1] = 0;
buffer[2] = 0;	

twi_packet_t packet = {
.addr = 0,
.addr_length = 1,
.buffer = buffer,
.chip = 0x60,
.length = 3
freertos_twi_if freertos_twi = freertos_twi_master_init(TWI0, &freertos_driver_parameters);
status_code_t status = freertos_twi_write_packet(freertos_twi, &packet, 200);

But freertos_twi_write_packet never return. Do I missing anything?



Does the whole system hang, or just the task calling that function. If the whole system, and you pause on the debugger, what is executing? If just that task, and you step into the function in the debugger, how far does it get?

Following is the call stack when I break,
Looks like exception happen and not handled.
maybe more init need to do before call them but not sure what is it.

XPA.elf! Dummy_Handler Line: 221

XPA.elf! Line: 221

XPA.elf! PendSV_Handler Line: 307

XPA.elf! Line: 307

XPA.elf! xQueueGenericReceive (xQueueHandle pxQueue, void * const pvBuffer, void * const pvBuffer@entry, portTickType xTicksToWait, long xJustPeeking, long xJustPeeking@entry) Line: 1093

XPA.elf! freertos_optionally_wait_transfer_completion (freertos_dma_event_control_t * dma_event_control, freertos_dma_event_control_t * dma_event_control@entry, xSemaphoreHandle notification_semaphore, xSemaphoreHandle notification_semaphore@entry, portTickType max_block_time_ticks) Line: 375

XPA.elf! freertos_twi_write_packet_async (freertos_twi_if p_twi, freertos_twi_if p_twi@entry, twi_packet_t * p_packet, twi_packet_t * p_packet@entry, portTickType block_time_ticks, portTickType block_time_ticks@entry, xSemaphoreHandle notification_semaphore, xSemaphoreHandle notification_semaphore@entry) Line: 480

XPA.elf! main Line: 186

Is the rest of your system functioning as expected (tasks switching, tick count incrementing) if you don’t call freertos_twi_write_packet() anywhere? Do you have the TWI interrupt installed? Do you have configASSERT() defined?

  1. Comment out freertos_twi_write_packet() my code runs well.

  2. The symptom is waiting for transmission complete forever. I think TWI interrupt is inside freertos_twi_master.c. I do add the following code before freertos_twi_master_init but still same result.
    PS: I do change my code from TWI0 to TWI1. Because according to Arduino due, TWI1 has pull up resister but TWI0 no.

    NVIC_SetPriority(TWI1_IRQn, 0);
    freertos_twi_if freertos_twi = freertos_twi_master_init(TWI1, &freertos_driver_parameters);

Do you really have TWI1_Handler defined somewhere ? That’s the required interrupt handler. Usually it‘s set up as interrupt handler (in exception table) by default as weak symbol which is aliased by Dummy_Handler if it‘s not defined in application code.


It was my fault that I put the code at the beginning of main. It is much better when I put the code in the beginning of a task.

Now the first freertos_twi_write_packet return 0
But second freertos_twi_write_packet return ERR_TIMEOUT at freertos_obtain_peripheral_access_semphore

Do I need to something after call freertos_twi_write_packet? or call freertos_twi_master_init everytime before freertos_twi_write_packet?



I just want to update the status.
I still cannot make freeRTOS work but my problem solved.
I add the following into conf_board.h and my Wire Library port from Arduino IDE to Atmel Studio 7 work.