PIC Vietnam

Go Back   PIC Vietnam > Truyền thông > Giao tiếp USB, CAN, I2C, SPI, USART...

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 18-11-2009, 06:50 PM   #16
minhtr123
Nhập môn đệ tử
 
Tham gia ngày: Nov 2008
Bài gửi: 9
:
Trích:
Nguyên văn bởi hopeman View Post
Thời gian vừa qua tôi tìm cách làm giao thức CAN nhưng tìm trên PICVN thấy cũng không nhiều lắm và có vẻ như cũng chưa có tiền bối nào dạy cụ thể việc này, sau một thời gian mò mẫm tôi đã làm được cho 2 em dsPIC30f4012 nói chuyện được với nhau (tất nhiên là có sự trợ giúp của 2 em MCP2551) nên tôi mở ra mục này để nếu ai quan tâm có thể cùng tham gia và tiếp cận nhanh hơn với CAN trên dsPIC mà ở đây tôi chọn ví dụ là con 30F4012
Đầu tiên nếu bạn quan tâm, xin hãy đọc bài cơ bản về CAN tại đây :
http://www.picvietnam.com/forum/showthread.php?t=1804
và hãy đọc về họ dsPIC30F đặc biệt là phần về CAN
http://ww1.microchip.com/downloads/e...Doc/70046E.pdf
đừng quên đọc về em dsPIC30f0412 Và em MCP2551 nữa nhé
sau đó chúng ta sẽ tiếp tục làm việc....
(tôi mặc định là các bạn đã biết dùng MPLab C30)
Nếu bạn còn vào Topic này thì có thê post Mạch nguyên lý Ko?
Mình dốt nặc Kĩ thuật nên ... mong bạn đừng cười. Mình đang lam CAN nhưng gặp khó khăn.
minhtr123 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 30-11-2009, 02:01 PM   #17
tahi
Đệ tử 4 túi
 
Tham gia ngày: Mar 2009
Bài gửi: 64
:
Em có thể tổng kết lại 1 cách cơ bản mối liên hệ giữa identifier, mask, và filter nhé. Các bác xem có gì sai xót thì sửa cho em. Em tham khảo tài liệu của dsPIC33F

identifier: có 2 loại là standard và extend (ở trong message của CAN bus)
mask : có 3 thằng mask được cấu hình bởi C1RXMiSID với standard và C1RXMiEID với extend (i =0,1,2)

filter: Có 16 thằng filter .Mỗi thằng filter gồm 2 thanh ghi cho standard id và extend id
C1RXFiSID,C1RXFiSED với i từ 0 đến 15,

Ví dụ:
- Về cơ bản truyển nhận CAN:
Node truyền gửi bản tin với 11 bít standard id (29 với extend). Các node nhận bóc lấy 11 bít này, so sánh từng bít với filter...Tại vị trí bít đó mà mask bằng 1, nếu bít của filter bằng bít của gói tin đuợc gửi đến...accepts, còn ko thì reject. Nếu mask = 0, thì accept tất mà không phụ thuộc vào filter của node nhận hay id của message tới. Phần này em đọc ở chỗ Mask truth table

- Cấu hình thằng nhận:
+ b1: Chọn mask (3 thằng) nào cho thằng filter nào (15 thằng). Gồm 2 thanh C1FMSKSEL1,C1FMSKSEL2
Code:
C1FMSKSEL1bits.F0MSK=0x0; //mask 0 cho filter 0
// =0x1 thì là mask 1, 0x2 thì là mask2,0x3 là mask3
// FiMSK gồm 2 bít, F1MSK là cấu hình mask cho thằng filter1
+ b2: thiết lập giá trị cho mask
Code:
C1RXM0SIDbits.SID = 0x7FF;//cấu hình mask0 cho standard id
+ B3: thiết lập giá trị cho filter
Code:
C1RXF0SIDbits.SID = 0x01D0; //cấu hình filter0 cho standard id
Còn lại những thứ khác như: chỉ nhận standard id hay chỉ nhận extend id, nguồn dao động ở đâu Fcy hay Fosc, các mode hoạt động ...

Khi truyền ECAN: Làm thế nào để biết đường truyền rỗi?
Nếu em muốn test ECAN của dsPIC33, em nối như sau : dspic33 ->mcp2551, đấu đường CAN_L và CAN_H với nhau, rồi xét ở mode normal hoặc loopback, thì có được không?

thay đổi nội dung bởi: tahi, 07-12-2009 lúc 04:08 PM.
tahi vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 10-03-2010, 03:52 AM   #18
tranthudo
Nhập môn đệ tử
 
Tham gia ngày: Mar 2008
Bài gửi: 6
:
Em copy nguyên code của bác mà không thấy nó truyền được. Em đã test thử nếu đổi về chế độ loopback thì nó truyền ngon, nhưng mà đổi sang chế độ normal nó không thấy truyền được.
Sau khi bit TXREQ được set lên thì cứ = 1 mãi. chắc là không truyền được. không hiểu có lỗi gì nữa nhỉ hic.
tranthudo vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 06-05-2010, 03:58 PM   #19
quocviet233
Nhập môn đệ tử
 
Tham gia ngày: Sep 2008
Bài gửi: 7
:
anh hopeman à, em copy code cua anh vào dich bằng C30 (hình như anh ko cùng các init_ADC10 phải không ạ?) thì nó hiện ra các cái lỗi như sau, em thấy nhiều quá nên ko biết mình còn sót cái j nữa ko? Anh xem giùm em nhé!
Debug build of project `C:\Documents and Settings\PHAMQUOCVIET\Desktop\CAN_C30\CAN_4012_tes t.mcp' started.
Language tool versions: pic30-as.exe v3.11, pic30-gcc.exe v3.11, pic30-ld.exe v3.11, pic30-ar.exe v3.11
Preprocessor symbol `__DEBUG' is defined.
Thu May 06 14:49:41 2010
----------------------------------------------------------------------
Make: The target "C:\Documents and Settings\PHAMQUOCVIET\Desktop\CAN_C30\Code_CAN_C30 _interrupt.o" is out of date.
Executing: "C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe" -mcpu=30F4012 -x c -c "Code_CAN_C30_interrupt.c" -o"Code_CAN_C30_interrupt.o" -D__DEBUG -g -Wall
Code_CAN_C30_interrupt.c:25: error: syntax error before '{' token
Code_CAN_C30_interrupt.c:39: warning: type defaults to 'int' in declaration of 'C1CFG2'
Code_CAN_C30_interrupt.c:39: error: conflicting type qualifiers for 'C1CFG2'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1849: error: previous declaration of 'C1CFG2' was here
Code_CAN_C30_interrupt.c:39: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:45: warning: type defaults to 'int' in declaration of 'C1INTF'
Code_CAN_C30_interrupt.c:45: error: conflicting type qualifiers for 'C1INTF'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1863: error: previous declaration of 'C1INTF' was here
Code_CAN_C30_interrupt.c:45: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:46: error: syntax error before '.' token
Code_CAN_C30_interrupt.c:47: warning: type defaults to 'int' in declaration of 'C1INTE'
Code_CAN_C30_interrupt.c:47: error: conflicting type qualifiers for 'C1INTE'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1885: error: previous declaration of 'C1INTE' was here
Code_CAN_C30_interrupt.c:47: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:48: error: syntax error before '.' token
Code_CAN_C30_interrupt.c:56: warning: type defaults to 'int' in declaration of 'C1RX0CON'
Code_CAN_C30_interrupt.c:56: error: conflicting type qualifiers for 'C1RX0CON'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1820: error: previous declaration of 'C1RX0CON' was here
Code_CAN_C30_interrupt.c:56: error: initializer element is not constant
Code_CAN_C30_interrupt.c:56: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:62: warning: type defaults to 'int' in declaration of 'C1RXM0SID'
Code_CAN_C30_interrupt.c:62: error: conflicting type qualifiers for 'C1RXM0SID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1591: error: previous declaration of 'C1RXM0SID' was here
Code_CAN_C30_interrupt.c:62: error: initializer element is not constant
Code_CAN_C30_interrupt.c:62: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:66: warning: type defaults to 'int' in declaration of 'C1RXM0EIDH'
Code_CAN_C30_interrupt.c:66: error: conflicting type qualifiers for 'C1RXM0EIDH'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1595: error: previous declaration of 'C1RXM0EIDH' was here
Code_CAN_C30_interrupt.c:66: error: initializer element is not constant
Code_CAN_C30_interrupt.c:66: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:70: warning: type defaults to 'int' in declaration of 'C1RXM0EIDL'
Code_CAN_C30_interrupt.c:70: error: conflicting type qualifiers for 'C1RXM0EIDL'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1598: error: previous declaration of 'C1RXM0EIDL' was here
Code_CAN_C30_interrupt.c:70: error: initializer element is not constant
Code_CAN_C30_interrupt.c:70: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:75: warning: type defaults to 'int' in declaration of 'C1RXF0SID'
Code_CAN_C30_interrupt.c:75: error: conflicting type qualifiers for 'C1RXF0SID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1523: error: previous declaration of 'C1RXF0SID' was here
Code_CAN_C30_interrupt.c:75: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:76: warning: type defaults to 'int' in declaration of 'C1RXF2SID'
Code_CAN_C30_interrupt.c:76: error: conflicting type qualifiers for 'C1RXF2SID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1543: error: previous declaration of 'C1RXF2SID' was here
Code_CAN_C30_interrupt.c:76: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:77: warning: type defaults to 'int' in declaration of 'C1RXF2EIDH'
Code_CAN_C30_interrupt.c:77: error: conflicting type qualifiers for 'C1RXF2EIDH'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1547: error: previous declaration of 'C1RXF2EIDH' was here
Code_CAN_C30_interrupt.c:77: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:78: warning: type defaults to 'int' in declaration of 'C1RXF2EIDL'
Code_CAN_C30_interrupt.c:78: error: conflicting type qualifiers for 'C1RXF2EIDL'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1550: error: previous declaration of 'C1RXF2EIDL' was here
Code_CAN_C30_interrupt.c:78: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:84: warning: type defaults to 'int' in declaration of 'C1TX0CON'
Code_CAN_C30_interrupt.c:84: error: conflicting type qualifiers for 'C1TX0CON'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1728: error: previous declaration of 'C1TX0CON' was here
Code_CAN_C30_interrupt.c:84: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:85: warning: type defaults to 'int' in declaration of 'C1TX0SID'
Code_CAN_C30_interrupt.c:85: error: conflicting type qualifiers for 'C1TX0SID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1704: error: previous declaration of 'C1TX0SID' was here
Code_CAN_C30_interrupt.c:85: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:86: warning: type defaults to 'int' in declaration of 'C1TX0EID'
Code_CAN_C30_interrupt.c:86: error: conflicting type qualifiers for 'C1TX0EID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1708: error: previous declaration of 'C1TX0EID' was here
Code_CAN_C30_interrupt.c:86: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:87: warning: type defaults to 'int' in declaration of 'C1TX0DLC'
Code_CAN_C30_interrupt.c:87: error: conflicting type qualifiers for 'C1TX0DLC'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1712: error: previous declaration of 'C1TX0DLC' was here
Code_CAN_C30_interrupt.c:87: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:91: warning: type defaults to 'int' in declaration of 'C1TX1CON'
Code_CAN_C30_interrupt.c:91: error: conflicting type qualifiers for 'C1TX1CON'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1700: error: previous declaration of 'C1TX1CON' was here
Code_CAN_C30_interrupt.c:91: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:92: warning: type defaults to 'int' in declaration of 'C1TX1SID'
Code_CAN_C30_interrupt.c:92: error: conflicting type qualifiers for 'C1TX1SID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1676: error: previous declaration of 'C1TX1SID' was here
Code_CAN_C30_interrupt.c:92: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:93: warning: type defaults to 'int' in declaration of 'C1TX1EID'
Code_CAN_C30_interrupt.c:93: error: conflicting type qualifiers for 'C1TX1EID'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1680: error: previous declaration of 'C1TX1EID' was here
Code_CAN_C30_interrupt.c:93: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:94: warning: type defaults to 'int' in declaration of 'C1TX1DLC'
Code_CAN_C30_interrupt.c:94: error: conflicting type qualifiers for 'C1TX1DLC'
c:/program files/microchip/mplab c30/bin/bin/../../support/dsPIC30F/h/p30F4012.h:1684: error: previous declaration of 'C1TX1DLC' was here
Code_CAN_C30_interrupt.c:94: warning: data definition has no type or storage class
Code_CAN_C30_interrupt.c:97: error: syntax error before '.' token
Code_CAN_C30_interrupt.c:222:2: warning: no newline at end of file
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\PHAMQUOCVIET\Desktop\CAN_C30\CAN_4012_tes t.mcp' failed.
Language tool versions: pic30-as.exe v3.11, pic30-gcc.exe v3.11, pic30-ld.exe v3.11, pic30-ar.exe v3.11
Preprocessor symbol `__DEBUG' is defined.
Thu May 06 14:49:44 2010
----------------------------------------------------------------------
BUILD FAILED
quocviet233 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 11-12-2011, 04:31 PM   #20
phuongvpmt
Nhập môn đệ tử
 
Tham gia ngày: Oct 2011
Bài gửi: 2
:
nhờ giúp về giao thức CAN

chào các anh
kỳ nạỳ e làm đồ án: truyền và nhận dữ liệu trong mang can sữ dụng vi xử lý của microchip, dùng protect để mô phỏng hiển thị nhiệt độ cảm biến được.
e không biết cách đấu mắc các chân của pic tới mcp 2551 và hiên thị ra màn hình lcd như thế nào
các anh có thể làm ơn hướng dẫn giúp em vẽ 1 mạch nguyên lý với
cảm ơn anh nhiều
phuongvpmt vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 27-12-2011, 11:37 PM   #21
phuongvpmt
Nhập môn đệ tử
 
Tham gia ngày: Oct 2011
Bài gửi: 2
:
nhờ giúp về giao thức CAN

cảm ơn anh
thật sự đây là lần tiên e tìm hiểu về can, mà tài liệu tiếng việt thì hiếm quá. ở trường thì em chỉ quen dùng ngôn ngữ assembly, trong chương trình anh viết em không hiểu được, mong anh thông cảm nha
e đang học tại đà nẵng, kỳ này em đang làm đồ án về: truyền và nhận dữ liệu trong mạng can sử dụng vi xử lý của microchip
em hơi kẹt không biết làm thế nào để viết chương trình cho giao thức CAN này anh có thể làm ơn chỉ cho em ít đường cơ bản được không a
mong sớm được hồi âm của anh
thân chào
phuongvpmt vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 03-01-2012, 09:22 AM   #22
tap_tanh
Nhập môn đệ tử
 
Tham gia ngày: Dec 2011
Bài gửi: 2
:
các bác cho em hỏi:
- khi truyền message thì chỉ có ID là dùng để nhận dạng message đó từ đâu tới thôi phải không? hay còn có phần nào khác nữa?
- một con trong mạng CAN có thể nhận message từ bao nhiêu con trong mạng vậy? bởi em định làm mạng CAN gồm 10-16 con giao tiếp với nhau.

Mong các bác giúp em. Cảm ơn nhiều!!
tap_tanh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 09-12-2017, 06:51 AM   #23
kikyou
Nhập môn đệ tử
 
Tham gia ngày: Jul 2017
Bài gửi: 1
:
hú hú có ai ko? :'(
kikyou vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 10:19 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam