pon., 26 sie 2024 o 16:20 Ujjval Rathod <ujjwalrathod...@gmail.com> napisaĆ(a): > > Hi, > > I was trying to port the note-c library to communicate with Blues wireless > notecard over I2C. > For that I created a package in the core repository and pasted all the > sources and headers. They are compelling when I build the code. > Then I wrote some MyNewt I2C API specific code. I took some inspiration from > the code of Zephyr-RTOS port. The code compiles fine but when I try to > communicate with notecard I get the following error. > The unhandled interrupt is from os_fault.c. But I do not understand why I am > getting this error. > I am using nRF52840-DK for my examples. > > Please see the attached code for more information. > > 000065 [ERROR] notecard not responding > 000130 [ERROR] notecard not responding > 000195 [ERROR] notecard not responding > 000260 [ERROR] notecard not responding > 000325 [ERROR] notecard not responding > 000390 [ERROR] notecard not responding > 000455 [ERROR] notecard not responding > 000520 [ERROR] notecard not responding > 000585 [ERROR] notecard not responding > 000650 [ERROR] notecard not responding > 000773 Unhandled interrupt (3), exception sp 0x20001370 > 000773 r0:0x00000000 r1:0x00017948 r2:0x00017763 r3:0x20000258 > 000773 r4:0x77630000 r5:0x00300001 r6:0x12b8dead r7:0xbeef2000 > 000773 r8:0x12c0dead r9:0x01062000 r10:0x12400a80 r11:0x77602000 > 000773 r12:0xa0000000 lr:0x00012505 pc:0x1a000000 psr:0x61000000 > 000773 ICSR:0x00421803 HFSR:0x40000000 CFSR:0x00000100 > 000773 BFAR:0xe000ed38 MMFAR:0xe000ed34 > > Regards, > Ujjval
Hi, here is Mynewt equivalent of Zephyr code. Previous version of both note_i2c_write and note_i2c_receive should look more like this. const char *note_i2c_receive(uint16_t device_address_, uint8_t *buffer_, uint16_t size_, uint32_t *available_) { //const int request_length = size_ + REQUEST_HEADER_SIZE; //request_length uint8_t size_buf[2]; size_buf[0] = 0; size_buf[1] = (uint8_t)size_; struct hal_i2c_master_data data = { .address = device_address_, .len = sizeof(size_buf), .buffer = size_buf, }; uint8_t write_result = hal_i2c_master_write(i2c_num, &data, OS_TICKS_PER_SEC / 10, 0); if (write_result != 0) { return "i2c: unable to initiate read from the notecard\n"; } // Read from the Notecard and copy the response bytes into the response buffer const int request_length = size_ + REQUEST_HEADER_SIZE; uint8_t read_buf[256]; data.len = request_length; data.buffer = read_buf; uint8_t read_result = hal_i2c_master_read(i2c_num, &data, OS_TICKS_PER_SEC / 10, 1); if (read_result != 0) { return "i2c: Unable to receive data from the Notecard.\n"; } else { *available_ = (uint32_t)read_buf[0]; uint8_t bytes_to_read = read_buf[1]; for (size_t i = 0; i < bytes_to_read; i++) { buffer_[i] = read_buf[i + 2]; } return NULL; } } ........ const char *note_i2c_transmit(uint16_t device_address_, uint8_t *buffer_, uint16_t size_) { uint8_t write_buf[size_ + 1]; write_buf[0] = (uint8_t)size_; for (size_t i = 0; i < size_; i++) { write_buf[i + 1] = buffer_[i]; } struct hal_i2c_master_data data = { .address = device_address_, .len = size_ + 1, .buffer = write_buf, }; uint8_t write_result = hal_i2c_master_write(i2c_num, &data, OS_TICKS_PER_SEC / 5, 1); if (write_result != 0) { return "i2c: Unable to transmit data to the Notecard\n"; } else { return NULL; } } best regards Jerzy